Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var libxmljs = require("libxmljs");
- var xmlDoc = libxmljs.parseXmlFile("sample.xml");
- xmlDoc.root().childNodes().length; // 5
- var libxmljs = require("libxmljs");
- var xmlDoc = libxmljs.parseXmlFile("sample.xml");
- xmlDoc.root().childNodes().length; // 5
- xmlDoc.root().childNodes()[0].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
- xmlDoc.root().childNodes()[1].get("Title").text(); // Title 1
- xmlDoc.root().childNodes()[2].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
- xmlDoc.root().childNodes()[3].get("Title").text(); // Title 2
- xmlDoc.root().childNodes()[4].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
- <?xml version="1.0" encoding="UTF-8"?>
- <ResultSet><Result><Title>Title 1</Title><Summary>Summary 1</Summary></Result><Result><Title>Title 2</Title><Summary>Summary 2</Summary></Result></ResultSet>
- xmlDoc.root().childNodes()[0].get("Title");
- xmlDoc.root().childNodes()[0].type() // 'text'
- xmlDoc.find('*')[0].get('Title').text() // 'Title 1'
- xmlDoc.find('*/Title')[0].text() // 'Title 1'
Add Comment
Please, Sign In to add comment