Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- 1 = video , 2 = html , 3 = pdf -->
<stage_type>2</stage_type>
<resource_name>http://www.XXX</resource_name>
I want to get <resource_name>
. I'm using xml2js.
When I use:
var parser = new xml2js.Parser();
fs.readFile('./' + file, function(err, data) {
parser.parseString(data, function (err, result) {
console.dir(result);
console.log('Done');
});
});
I got <stage_type>
and no all xml file. (<stage_type>
and <resource_name>
).
I know that I don't have a root tag, but I need to leave it like that.
Your XML file isn't valid XML. It has multiple root nodes. Try parsing XML like this and it should work:
You could rename that
resource
node to whatever you want, but that's whyxml2js
is missing theresource_name
. I don't know of any option to havexml2js
process a fragment (which might make it accept this type of XML).