how to parse a xml file ......using parsexmlfile() method.....is there any inbuilt method such as for parsing a xml file ..i dont want to copy and paste my xml manually...i hv xml file in my drive saved.

822 views
Skip to first unread message

spp

unread,
Aug 13, 2013, 2:18:12 AM8/13/13
to libx...@googlegroups.com
Hi All,

i want to parse  a xml file stored in my drive..i want to use in-built method such as- parsexmlfile()..i dont want to copy and paste my xml ..and also i want to see my doc version in xml parsed result...



any clue?

regards,
shailendra


Stephen Veit

unread,
Aug 13, 2013, 9:51:43 AM8/13/13
to libx...@googlegroups.com
Shailendra,

Try this program:

#!/usr/bin/env node

var libxmljs = require('libxmljs');
var fs = require('fs');

function parseXmlFile(filename) {
  fs.readFile(filename, function (err, contents) {
    if (err) {
      console.error('error reading file', filename + ':', err);
      return;
    }
    var xml = libxmljs.parseXmlString(contents);
    console.log(xml.version());
    console.log(xml.root().name());
  });
}

parseXmlFile(process.argv[2]);

And call like this:

node parse-xml.js sample.xml


Hope this helps.

--
You received this message because you are subscribed to the Google Groups "libxmljs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libxmljs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Stephen Veit
314-616-9688

vibhuti chandra

unread,
May 21, 2017, 3:21:48 PM5/21/17
to libxmljs
Hi,

can you please tell how to get the whole data of .xml file printed similar to version and name?

and can you please tell, how would I come to know that what are the functions a node module has?
for example you have used a function "parseXmlString" in this line?  var xml = libxmljs.parseXmlString(contents);

Thanks
Vibhuti

Stephen Veit

unread,
May 22, 2017, 8:40:04 AM5/22/17
to libx...@googlegroups.com
You can find the documentation for the libxmljs functions here: https://github.com/libxmljs/libxmljs/wiki

To unsubscribe from this group and stop receiving emails from it, send an email to libxmljs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen Veit
314-616-9688
Reply all
Reply to author
Forward
0 new messages