struggling with xpath to find a element mathing a value

65 views
Skip to first unread message

Dinesh Rampal

unread,
Jan 25, 2018, 6:06:53 AM1/25/18
to libxmljs
Hi All

I have spent close to two days struggling to find a element matching a value.

my xml looks like this :

<xml>
    <qdbapi>
      <record>
                    <sku_plant>abcd</sku_plant>
                    <sku>ab</sku>
                     <plant>cd</plant>
      </record>
      <record>
                    <sku_plant>efgh</sku_plant>
                    <sku>ef</sku>
                     <plant>gh</plant>
      </record>
      <record>
                    <sku_plant>ijkl</sku_plant>
                    <sku>ij</sku>
                     <plant>kl</plant>
      </record>
    </qdbapi>
</xml>

I am trying to use xmlfinaldoc.find( ) like following, but it gets all sku_plant, rather than the one which i want;

               var x='/qdbapi/record/sku_plant/text()[contains(.,efgh)]';
         var arr = xmlFinalDoc.find(x);

The array arr returns all the element and not the one i want. Where am i going wrong ? How can i find the object record which has a sku_plant (efgh). In my design sku_plant is unique across all records.

thanks 
dinesh

Stephen Veit

unread,
Jan 25, 2018, 9:50:00 AM1/25/18
to libx...@googlegroups.com
Dinesah,

Try this XPath instead:

var x='//qdbapi/record/sku_plant[contains(text(),\'efgh\')]';


--
You received this message because you are subscribed to the Google Groups "libxmljs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libxmljs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen Veit
314-616-9688
Reply all
Reply to author
Forward
0 new messages