We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XMLBuilder outputs empty line at the start of output, which breaks some XML processors.
According to: https://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node46.html#:~:text=The%20first%20line%20of%20an,encoding%20used%20in%20the%20file.
The first line of an XML document should be a declaration that this is an XML document, including the version of XML being used.
Specifically first line, not second line. Even if first line is empty string.
"fast-xml-parser": "^4.0.6"
<?xml version="1.0" encoding="UTF-8"?> <testsuites> </testsuites>
import { XMLParser, XMLBuilder, XMLValidator } from "fast-xml-parser"; import fs from "fs"; const parser = new XMLParser({ ignoreAttributes: false, preserveOrder: true, cdataPropName: "__cdata", }); console.info("Parsing junit.xml ..."); const origXml = fs.readFileSync("junit.xml"); const jObj = parser.parse(origXml); console.debug("Original XML:", origXml.toString("utf8")); console.info("Parsed."); // ... const builder = new XMLBuilder({ ignoreAttributes: false, preserveOrder: true, cdataPropName: "__cdata", format: true, }); // console.log(builder.build(jObj)); console.debug(builder.build(jObj)); console.info("Saving to junit.xml ..."); fs.writeFileSync("junit.xml", builder.build(jObj), { encoding: "utf8" }); console.info("Saved.");
<?xml version="1.0"
use String.trimStart()
String.trimStart()
Would you like to work on this issue?
Bookmark this repository for further updates.
The text was updated successfully, but these errors were encountered:
I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.
Sorry, something went wrong.
1f5b0a7
Thank you @amitguptagwl 🙏
No branches or pull requests
Description
XMLBuilder outputs empty line at the start of output, which breaks some XML processors.
According to: https://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node46.html#:~:text=The%20first%20line%20of%20an,encoding%20used%20in%20the%20file.
Specifically first line, not second line. Even if first line is empty string.
Input
Code
Output (buggy)
<?xml version="1.0"
has too much spaceexpected output
workaround
use
String.trimStart()
Would you like to work on this issue?
Bookmark this repository for further updates.
The text was updated successfully, but these errors were encountered: