Forked from benvium/react-native-parse-xml-example.js
Created
October 25, 2016 13:14
-
-
Save kevinold/1d16631a4603d639638f45c85245877d to your computer and use it in GitHub Desktop.
Parse XML Example using React Native.xmldom is a pure JavaScript implementation of an XML Parser. I've added it to window so that browser modules that require it will work. Tested on iOS and Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Before use, type: | |
* ``` | |
* npm install xmldom --save | |
* ``` | |
*/ | |
window.DOMParser = require('xmldom').DOMParser; | |
const exampleParse = ()=> { | |
const text = `<bookstore> | |
<book category="cooking"> | |
<title lang="en">Everyday Italian</title> | |
<author>Giada De Laurentiis</author> | |
<year>2005</year> | |
<price>30.00</price> </book> | |
<book category="children"> | |
<title lang="en">Harry Potter</title> | |
<author>J K. Rowling</author> | |
<year>2005</year> | |
<price>29.99</price> </book> | |
<book category="web"> | |
<title lang="en">XQuery Kick Start</title> | |
<author>James McGovern</author> | |
<author>Per Bothner</author> | |
<author>Kurt Cagle</author> | |
<author>James Linn</author> | |
<author>Vaidyanathan Nagarajan</author> | |
<year>2003</year> | |
<price>49.99</price> </book> | |
<book category="web" cover="paperback"> | |
<title lang="en">Learning XML</title> | |
<author>Erik T. Ray</author> | |
<year>2003</year> | |
<price>39.95</price> </book> | |
</bookstore>`; | |
const parser = new DOMParser(); | |
const xmlDoc = parser.parseFromString(text); | |
console.log("XmlTest.exampleParse " + xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue); | |
}; | |
module.exports = exampleParse | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment