Javascript - Handing XML document with prefix and name space

If you need to process XML string with namespace such as 
"<book xmlns:xi='http://www.w3.org/2001/XInclude'>
    <Name>Some text</Name>
    <Price>$12</Price></book>" 
, then you can use "getElementsByTagNameNS" function to process it. Its formula is: elements = element.getElementsByTagNameNS(namespaceURI, localName)


Below code is th example of using  "getElementsByTagNameNS" function and explore XML child nodes  in JavaScript.
var z=xmlDocument.getElementsByTagNameNS('http://schemas.microsoft.com/ado/2007/08/dataservices', 'Rows');
x=z[0].firstElementChild.childNodes;
for (i = 0; i < x.length ;i++) {     console.log(x[i].firstChild);
      if (x[i].firstChild.innerHTML=="URL")       {
                  console.log(x[i].children[1].innerHTML);
      }
  }  

Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

SharePoint 2013 error - "Application error when access /_vti_bin/client.svc"

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search