feat(core): Upgrade dependencies and enhance XML parsing and building
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartxml',
|
||||
version: '1.0.8',
|
||||
description: 'a package for creating and parsing xml formated files'
|
||||
version: '1.1.0',
|
||||
description: 'A package for creating and parsing XML formatted files.'
|
||||
}
|
||||
|
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