0

how to extract option value from text by regex or xpath from the below response

xpath extractor

 //*[@id="form_extsss:fromSerie2"]/option[text()='-DRIVE_ME']/@value

for example:

option value for -DRIVE_ME is 630 (expecting the 630 as final value)

Response

    <?xml version="1.0" encoding="UTF-8"?>
<partial-response>
   <changes>
      <update id="form_extsss"><![CDATA[<form id="form_extsss" name="form_extsss" 
      method="post" action="" enctype="multipart/form-data">
        <select id="form_extsss:fromSerie2" name="form_extsss:fromSerie2" size="1" onchange="PrimeFaces.ab({s:&quot;form_extsss:fromSerie2&quot;,e:&quot;valueChange&quot;,p:&quot;form_extsss:fromSerie2&quot;,u:&quot;form_extsss&quot;});" style="width:110px">  <option value="-1">Select Series</option>   
        <option value="1384">-HAD</option>  
        <option value="630">-DRIVE_ME</option>
        </select>                       
                                    </form>]]></update>
      <update id="javax.faces.ViewState"><![CDATA[]]></update>
   </changes>
</partial-response>
senthil kumar
  • 237
  • 1
  • 6
  • 18

3 Answers3

0
<option value="630">

The below Regular expression can be used in regular expression extractor:-

<option value="(.\d*)">
Rahul
  • 306
  • 2
  • 4
0

Using xpath won't work because of CDATA is represented as string only.

However if you have xquery available do

let $x := <partial-response>
    <changes>
      <update id="form_extsss"><![CDATA[<form id="form_extsss" name="form_extsss" method="post" action="" enctype="multipart/form-data">
      <select id="form_extsss:fromSerie2" name="form_extsss:fromSerie2" size="1"  onchange="PrimeFaces.ab({s:&quot;form_extsss:fromSerie2&quot;,e:&quot;valueChange&quot;,p:&quot;form_extsss:fromSerie2&quot;,u:&quot;form_extsss&quot;});" style="width:110px">
        <option value="-1">Select Series</option>   
        <option value="1384">-HAD</option>  
        <option value="630">-DRIVE_ME</option>
      </select>                       
                                </form>]]></update>
      <update id="javax.faces.ViewState"><![CDATA[]]></update>
    </changes>
  </partial-response>

return parse-xml($x/changes/update/text())/form/select/option/@value
Christian
  • 1,664
  • 1
  • 23
  • 43
0

Check if the below regex helps with your scenerio:- enter image description here enter image description here

sunny_teo
  • 1,961
  • 1
  • 7
  • 11