XML prolog is included as "?xml" property in json output
- [x] Are you running the latest version?
- [x] Have you included sample input, output, error, and expected output?
- [x] Have you checked if you are using correct configuration?
- [x] Did you try online tool?
- [x] Have you checked the docs for helpful APIs and examples?
Description
- Go to https://naturalintelligence.github.io/fast-xml-parser
- Click "Parse to JSON"
- Click "Parse to XML"
- Click "Parse to JSON"
- See error "Error: XML declaration allowed only at the start of the document.:2:6" in JSON panel
Input
(any XML code containing the prolog)
Code
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Output
{
"?xml": "",
"note": {
"to": "Tove",
"from": "Jani",
"heading": "Reminder",
"body": "Don't forget me this weekend!"
}
}
expected data
{
"note": {
"to": "Tove",
"from": "Jani",
"heading": "Reminder",
"body": "Don't forget me this weekend!"
}
}
Would you like to work on this issue?
- [X] Yes
- [ ] No
Bookmark this repository for further updates. Visit SoloThought to know about recent features.
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.
This is the issue in demo as <?xml version="1.0"?> is hard coded. no issue in the parser or builder
So you want both xml prologs in /index.html removed right?
no issue in the parser or builder
Are you sure about this? The following test fails if the xml prolog is present. Removing the xml prolog make the test pass.
describe("XMLParser with prolog", function () {
const xmlData = `<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
</note>`;
const expected = {
"note": {
"to": "Tove",
}
};
it("should parse XML prolog correctly", function () {
const parser = new XMLParser();
const result = parser.parse(xmlData);
expect(result).toEqual(expected);
});
});