Guest User

Untitled

a guest
Jul 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. var libxmljs = require("libxmljs");
  2. var xmlDoc = libxmljs.parseXmlFile("sample.xml");
  3. xmlDoc.root().childNodes().length; // 5
  4.  
  5. var libxmljs = require("libxmljs");
  6. var xmlDoc = libxmljs.parseXmlFile("sample.xml");
  7. xmlDoc.root().childNodes().length; // 5
  8.  
  9. xmlDoc.root().childNodes()[0].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
  10. xmlDoc.root().childNodes()[1].get("Title").text(); // Title 1
  11. xmlDoc.root().childNodes()[2].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
  12. xmlDoc.root().childNodes()[3].get("Title").text(); // Title 2
  13. xmlDoc.root().childNodes()[4].get("Title").text(); // TypeError: Cannot call method 'text' of undefined
  14.  
  15. <?xml version="1.0" encoding="UTF-8"?>
  16. <ResultSet><Result><Title>Title 1</Title><Summary>Summary 1</Summary></Result><Result><Title>Title 2</Title><Summary>Summary 2</Summary></Result></ResultSet>
  17.  
  18. xmlDoc.root().childNodes()[0].get("Title");
  19.  
  20. xmlDoc.root().childNodes()[0].type() // 'text'
  21.  
  22. xmlDoc.find('*')[0].get('Title').text() // 'Title 1'
  23.  
  24. xmlDoc.find('*/Title')[0].text() // 'Title 1'
Add Comment
Please, Sign In to add comment