xml - Xpath test with namespace -


in following example 1 access value vdd units of ds2438 can use following syntax:

  • (//*[local-name() = 'vdd'])[2] find 5.550000 and
  • (//*[local-name() = 'vdd'])[1] find 4.280000.

each <owd_ds2438> linked physical captor, each 1 of identified unique id <romid>. position in xml file can change.

question : how can find same value in 2 following examples specific <romid> using xpath?

example 1:

<?xml version="1.0" encoding="utf-8"?> <devices-detail-response xmlns="http://www.embeddeddatasystems.com/schema/owserver" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <devicename>owserver_v2-enet</devicename>     <hostname>edsowserver2</hostname>     <macaddress>00:04:a3:f8:62:7b</macaddress>     <datetime>2014-09-06 01:02:39</datetime>     <owd_ds2438 description="smart battery monitor">         <name>ds2438</name>         <romid>c100000140abc126</romid>         <temperature units="centigrade">20.9375</temperature>         <vdd units="volts">4.280000</vdd>         <vad units="volts">10.230000</vad>     </owd_ds2438>     <owd_ds2438 description="smart battery monitor">         <name>ds2438</name>         <romid>c100000140abc127</romid>         <temperature units="centigrade">20.9375</temperature>         <vdd units="volts">5.550000</vdd>         <vad units="volts">10.230000</vad>     </owd_ds2438> </devices-detail-response> 

example 2:

<?xml version="1.0" encoding="utf-8"?> <devices-detail-response xmlns="http://www.embeddeddatasystems.com/schema/owserver" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <devicename>owserver_v2-enet</devicename>     <hostname>edsowserver2</hostname>     <macaddress>00:04:a3:f8:62:7b</macaddress>     <datetime>2014-09-06 01:02:39</datetime>     <owd_ds2438 description="smart battery monitor">         <name>ds2438</name>         <romid>c100000140abc127</romid>         <temperature units="centigrade">20.9375</temperature>         <vdd units="volts">5.550000</vdd>         <vad units="volts">10.230000</vad>     </owd_ds2438>     <owd_ds2438 description="smart battery monitor">         <name>ds2438</name>         <romid>c100000140abc126</romid>         <temperature units="centigrade">20.9375</temperature>         <vdd units="volts">4.280000</vdd>         <vad units="volts">10.230000</vad>     </owd_ds2438> </devices-detail-response> 

thanks in advance stephane

sticking same approach local-name() use xpath expression

//*[local-name() = 'owd_ds2438' , *[local-name() = 'romid'] = 'c100000140abc127']/*[local-name() = 'vdd']/text() 

to select specific value romid.

however, context of question not clear me why need ignore namespaces. may more practical not ignore them. in case xpath simplify

//owd_ds2438[romid = 'c100000140abc127']/vdd/text() 

which more readable (imho). require, however, register default name space in xpath tool/library.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -