'fast-xml-paser remove unwanted tags
So every time that i want to build a new xml file the xml builder adds xml and stylsheet tags i would much rather add them myself or know how i could edit the content inside of it since i need to link the document to a specific stylesheet.
<?xml></?xml>
<?xml-stylesheet></?xml-stylesheet>
<schedule>
<event>
<title>IMY 210 Classes</title>
<type>Event</type>
<date>
<day>2</day>
<month>March</month>
<startingTime>03:30 PM</startingTime>
<endingTime>04:30 PM</endingTime>
</date>
<guests>
<guest>
<name>Yan</name>
<email>[email protected]</email>
</guest>
<guest>
<name>Daddy</name>
<email>[email protected]</email>
</guest>
</guests>
<venue>IT building</venue>
<description>World worst brain surgeon giving class on XML.</description>
</event>
this is the output but i want lines 1 and to go the passer that i use is called fast-xml-paser
and here is my code for writing this into a file the code get a JS object and appends it to the current JS ob that has the previous code on there from that i just go and re wright into the datafile but then i get the above mentioned output
app.post('/data', (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
const parser = new XMLParser();
const options = {
processEntities:false,
format: true,
}
const builder = new XMLBuilder(options);
var oldJ;
fs.readFile(dataFile, (err, rdata) => {
oldJ = parser.parse(rdata);
var num = Object.keys(oldJ).length;
console.log(num);
// res.send();
// oldJ.schedule['event'][num] = req.body;
var ans = builder.build(oldJ);
var xmlheaders = '<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="output.xsl"?>';
// oldJ.schedule['event'][]
fs.appendFileSync(dataFile,ans, (err) => {
if(err)
throw err;
})
res.send(ans);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
