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

Effective LLM Prompting skills

How to replace the OOTB SharePoint Help with your custom help page