Exception converting json back to xml
See original GitHub issueI need to use this module for a project to do some processing on XML --> JSON --> XML.
Checked out the code today and apply it on the xml from here: https://raw.githubusercontent.com/GovReady/govready/master/prototypes/ssg-rhel6-oval.xml
Got error
/Users/jdole/learn/node/node_modules/fast-xml-parser/src/xmlstr2xmlnode.js:48
xmlData = xmlData.replace(/<!--[\s\S]*?-->/g, "");//Remove comments
^
TypeError: xmlData.replace is not a function
at Object.getTraversalObj (/Users/jdole/learn/node/node_modules/fast-xml-parser/src/xmlstr2xmlnode.js:48:23)
at Object.exports.parse (/Users/jdole/learn/node/node_modules/fast-xml-parser/src/parser.js:10:50)
at Object.<anonymous> (/Users/jdole/learn/node/xml2js.js:26:20)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
The code snippet is adopted from your example.
var parser = require('fast-xml-parser');
var he = require('he');
var fs=require("fs");
var options = {
attributeNamePrefix : "@_",
attrNodeName: "attr", //default is 'false'
textNodeName : "#text",
ignoreAttributes : false,
ignoreNameSpace : false,
allowBooleanAttributes : false,
parseNodeValue : true,
parseAttributeValue : false,
trimValues: true,
cdataTagName: "__cdata", //default is 'false'
cdataPositionChar: "\\c",
localeRange: "", //To support non english character in tag/attribute values.
parseTrueNumberOnly: false,
attrValueProcessor: a => he.decode(a, {isAttributeValue: true}),//default is a=>a
tagValueProcessor : a => he.decode(a) //default is a=>a
};
xml=fs.readFileSync("ssg-rhel6-oval.xml", "utf8");
var result1;
var jsonObj = parser.parse(xml,options);
console.log(parser.parse(jsonObj))
Is this a bug in this module?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
How to convert JSON to XML or XML to JSON? - Stack Overflow
But if you do it, first convert from json to object, then from object to xml (and vice versa for reverse direction). Doing...
Read more >Converting between JSON and XML - Json.NET
The JsonConvert has two helper methods for converting between JSON and XML. The first is SerializeXmlNode(). This method takes an XmlNode and serializes...
Read more >Convert a JSON object to XML format in Java? - Tutorialspoint
We can convert a JSONObject into an XML format using org.json.XML class, this provides static methods to convert an XML text into a...
Read more >Question about "Failed to convert JSON file to XML" Error ...
Error: Failed to convert JSON file to XML. org.jitterbit.integration.server.engine.EngineSessionException: com.fasterxml.jackson.core.
Read more >How to convert Json to Xml & Xml to Json In Java with Maven
How to convert Json to Xml & Xml to Json In Java with Maven In this tutorial we will learn how to convert...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem he faced was, like mine, that he didn’t convert the file contents to a string.
This causes the error:
And this works:
I’ve just tested your file. everything looks fine to me.