Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get elements by tag name in an XML?

jesusemelendezm
Mega Guru

Hi

I have the following piece of XML and trying to parse it. I am using a client callable script include.

I need to get all the elements that are tagged with "<name>".

<l:cellphone>

<name>data_type</name>

<value>1X</value>

</l:cellphone>

<l:cellphone>

<name>sms</name>

<value>none</value>

</l:cellphone>

<l:cellphone>

<name>voice</name>

<value>none</value>

</l:cellphone>

<l:cellphone>

<name>wifi</name>

<value>wifi.net</value>

</l:cellphone>

I have tried the following 'getElementByTagName' but the script doesn't even run when that line is in. I have parsed other elements with getNodeText and that works but will only get the first element that is tagged with 'name'.

x = xmlDoc.getElementsByTagName("name")[0];// when this is in script stop running at that line and no getting anything on logs.

XML DOM - Get Node Values

Thanks for your help

10 REPLIES 10

Berny


My code stops in this line var reg = new SNC.Regex("/<name>([(.*)^[^<]]+)/");


I am using a script include ajax... I was checking whether the regex can be used in client callable script include.