Open joneqian opened 1 year ago
Only set textNodeName, and attributeNamePrefix is empty string, build result is error.
Example:
const schema_obj = { field: { values: { value: { '#text': 10061001, size: '5', }, }, id: 'skuCombineContent', type: 'multiInput', }, }; const parse_options = { ignoreAttributes: false, attributeNamePrefix: '', textNodeName: '#text', }; const builder = new XMLBuilder(parse_options); const schema_xml = builder.build(schema_obj);
Please mention the type of PR
Test code:
it('xml build test', async () => { const schema_obj = { field: { values: { value: { '#text': 10061001, size: '5', }, }, id: 'skuCombineContent', name: 'skuProduct', type: 'multiInput', }, }; const parse_options = { ignoreAttributes: false, attributeNamePrefix: '', textNodeName: '#text', }; const builder = new XMLBuilder(parse_options); const schema_xml = builder.build(schema_obj); console.log(schema_xml); });
The current code execution results:
<field id="skuCombineContent" name="skuProduct" type="multiInput"><values><value #text="10061001" size="5"></value></values></field>
Modify isAttribute in json2xml.js
isAttribute
function isAttribute(name /*, options*/) { if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) { return name.substr(this.attrPrefixLen); } else { return false; } }
Get the accurate results:
<field id="skuCombineContent" name="skuProduct" type="multiInput"><values><value size="5">10061001</value></values></field>
We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.
Purpose / Goal
Only set textNodeName, and attributeNamePrefix is empty string, build result is error.
Example:
Type
Please mention the type of PR
Test code:
The current code execution results:
Modify
isAttribute
in json2xml.jsGet the accurate results: