0

I have an xml like this as mentioned below. I am trying to obtain value for 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

4

3 回答 3

0

xmlns:ns0放错地方了,并且(想想这种方式)因为ns0 <ns0:submit>标签之后定义的,ns0:submit是“未定义的”,因此是解析错误。

编辑

如果你需要在 PHP 中使用这个 XPath,你要么必须在使用前声明命名空间:

<?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>

或者在评估您的 XPath 之前注册命名空间(感谢@MiMo 指出):

$xml->registerXPathNamespace("ns0","http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd");

还要在 XPATH 之前添加一个斜杠:

/paymentService/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber

先声明的现场演示或名称空间注册的现场演示(均在 PHP 中演示)。

于 2013-04-25T11:38:01.077 回答
0

问题是节点

<paymentService version="1.0">

由于这没有结束,您必须对其进行评论或正确结束。如果您发表评论,请尝试使用此 XPATH

/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber
于 2013-04-25T11:28:13.390 回答
0

您需要在评估 XPath 之前注册命名空间:

$xml->registerXPathNamespace('ns0', 'http://www.tibco.com/ns/no_namespace_schema_location/Payment/PaymentProcessors/WorldPay_CC/SharedResources/Schemas/paymentService_v1.dtd');

where$xml是一个SimpleXMLElement包含您的 XML 的变量。

您的 XPath 需要/按照 Passerby 的答案开始:

/paymentService/ns0:submit/ns0:order/ns0:paymentDetails/ns0:VISA-SSL/cardNumber
于 2013-04-25T13:34:48.310 回答