AnsweredAssumed Answered

function contains() as part of xpath expression

Question asked by tonsh03 Employee on Sep 25, 2014

We can use xpath expression to check for specific text as part of XML tag elements and extract that data to be used as part of PAM

 

Example of xpath expression that uses contains() considering the following XML

 

 

<form>

<form xsi:type="ns2:FormElement">

       <ID xsi:type="xsd:string">CAT_EMAIL</ID>

       <label xsi:type="xsd:string">CAT_EMAIL</label>

       <labelValue xsi:nil="true" xsi:type="xsd:string" />

       <type xsi:type="xsd:int">5</type>

       <value xsi:type="xsd:string">EMAIL</value>

     </form>

     <form xsi:type="ns2:FormElement">

       <ID xsi:type="xsd:string">HID_EMAIL</ID>

       <label xsi:type="xsd:string">HID_EMAIL</label>

       <labelValue xsi:nil="true" xsi:type="xsd:string" />

       <type xsi:type="xsd:int">5</type>

       <value xsi:type="xsd:string">EMAIL</value>

     </form>

     <form xsi:type="ns2:FormElement">

       <ID xsi:type="xsd:string">HID_EMAIL1</ID>

       <label xsi:type="xsd:string">HID_EMAIL1</label>

       <labelValue xsi:nil="true" xsi:type="xsd:string" />

       <type xsi:type="xsd:int">5</type>

       <value xsi:type="xsd:string">EMAIL</value>

     </form>

</form>

 

 

Xpath Expression:

//form/ID[contains(text(),'HID')]/../value/text()

 

 

As part of this example it check is tag <ID></ID> contains HID value , returns data from tag <value></value> for all matching entries

 

 

The same can be used as part of applyXPath() function as follows

 

 

Process.CatValue = applyXPath(Process.Form_Data_Xml,"//form/ID[contains(text(),'HID')]/../value/text()",false,true);

 

 

This returns an array with values stored as part of Process.CatValue[]

Outcomes