feat(core): Upgrade dependencies and enhance XML parsing and building
This commit is contained in:
18
ts/index.ts
18
ts/index.ts
@@ -4,19 +4,25 @@ export class SmartXml {
|
||||
constructor() {}
|
||||
|
||||
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
||||
const parser = new plugins.fastXmlParser.XMLParser();
|
||||
const parser = new plugins.fastXmlParser.XMLParser({
|
||||
preserveOrder: true,
|
||||
ignoreAttributes: false,
|
||||
parseTagValue: true,
|
||||
parseAttributeValue: true,
|
||||
// ignoreDeclaration: true
|
||||
});
|
||||
const jsonObject = parser.parse(xmlStringArg);
|
||||
return jsonObject;
|
||||
return jsonObject as T;
|
||||
}
|
||||
|
||||
public createXmlFromObject(jsObject: any): string {
|
||||
const jsToXmlParser = new plugins.fastXmlParser.XMLBuilder({
|
||||
const builder = new plugins.fastXmlParser.XMLBuilder({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: "@_",
|
||||
attributeNamePrefix: '@_',
|
||||
format: true,
|
||||
indentBy: ' ',
|
||||
indentBy: ' '
|
||||
});
|
||||
const xml = jsToXmlParser.build(jsObject);
|
||||
const xml = builder.build(jsObject);
|
||||
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user