XPATH Error : Unable to evaluate expression -


i have xml mentioned below. trying obtain value cardnumber using following expression.

xpath :

paymentservice/ns0:submit/ns0:order/ns0:paymentdetails/ns0:visa-ssl/cardnumber 

but it's giving me error. can any1 guide me on this?

<?xml version="1.0" encoding="utf-8"?> <paymentservice version="1.0">     <ns0:submit xmlns:ns0="http://www.tibco.com/ns/no_namespace_schema_location/payment/paymentprocessors/worldpay_cc/sharedresources/schemas/paymentservice_v1.dtd">         <ns0:order>             <description>description</description>             <amount value="500" currencycode="eur" exponent="2"/>             <ns0:paymentdetails>                 <ns0:visa-ssl>                     <cardnumber>00009875083428500</cardnumber>                     <expirydate>                         <date month="02" year="2008"/>                     </expirydate>                     <cardholdername>test</cardholdername>                 </ns0:visa-ssl>                 <session shopperipaddress="192.165.22.35" id=""/>             </ns0:paymentdetails>             <shopper>                 <browser>                     <acceptheader>text/html</acceptheader>                     <useragentheader>mozilla 5.0</useragentheader>                 </browser>             </shopper>         </ns0:order>     </ns0:submit> </paymentservice> 

thanks

your xmlns:ns0 misplaced, , (think of way) because ns0 defined after <ns0:submit> tag, ns0:submit "undefined" , parse error.

edit:

if need use xpath in php, you'll either have declare namespace before use:

<?xml version="1.0" encoding="utf-8"?> <paymentservice version="1.0" xmlns:ns0="http://www.tibco.com/ns/no_namespace_schema_location/payment/paymentprocessors/worldpay_cc/sharedresources/schemas/paymentservice_v1.dtd">     <ns0:submit> 

or register namespace before evaluating xpath (thanks @mimo pointing out):

$xml->registerxpathnamespace("ns0","http://www.tibco.com/ns/no_namespace_schema_location/payment/paymentprocessors/worldpay_cc/sharedresources/schemas/paymentservice_v1.dtd"); 

also add slash before xpath:

/paymentservice/ns0:submit/ns0:order/ns0:paymentdetails/ns0:visa-ssl/cardnumber 

live demo declaration first or live demo namespace registration (both demonstrated in php).


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -