javascript - AngularJS getting XML child node -
i trying parse xml using angularjs , utilize here: https://github.com/johngeorgewright/angular-xml
this works great xml format:
<parent> <child id="1" name="something" attribute="something-else"/> </parent>
however, xml i'm trying parse in format:
<parent> <child> <grandchild1>lorem</grandchild1> <grandchild2>ipsum</grandchild2> <grandchild3>dolor</grandchild3> </child> <child> <grandchild1>lorem</grandchild1> <grandchild2>ipsum</grandchild2> <grandchild3>dolor</grandchild3> </child> </parent>
my question is, how loop through each of kid nodes respective grandchild nodes' properties?
thank you.
use iterator function:
function iterator(node) { var foo = node.nodevalue; homecoming foo; }
along parser function:
function parser(node); { /* transform childnodes array of values */ var bar = array.prototype.map.call(node.childnodes, iterator); homecoming bar; }
along query function:
function xmlquery(doc, node) { /* aggregate matching nodes */ var baz = doc.getelementsbytagname(node); homecoming array.prototype.map.call(baz, parser); }
and domparser:
function readxml(xmlfromajax) { /* xml response text */ var xmlstring = xmlfromajax; /* parse xml , query */ (new domparser) { var xmldom = parsefromstring(xmlstring, "text/xml"); console.log(xmldom.documentelement.nodename); homecoming xmlquery(xmldom, "child"); } }
references
domparser's parsefromstring function , ie 9
the tiny table sorter - or - can write linq in javascript
javascript array extras in detail
javascript xml angularjs
No comments:
Post a Comment