0

I have this security envelope. How do I navigate to the Timestamp node inside Secuirty something like this /Envelope/Header/Security/TimeStamp

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsse:Security soap:mustUnderstand="1"><wsu:Timestamp wsu:Id="Timestamp-dd0398f4-0844-4de9-997e-1fcbd7febd54"><wsu:Created>2013-06-21T04:25:00Z</wsu:Created>
 <wsu:Expires>2013-06-21T04:30:00Z</wsu:Expires></wsu:Timestamp><wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" 

Thank you

4

1 回答 1

0

Your XML includes namespaces, which you either

  • Have to register and use all namespaces (rather similar like Sridhar proposed but for the wrong slashes)

    /soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp
    

    Registering the namespaces heavily differs from programming language to programming language and XPath processor used, so you will have to look that up in the appropriate documentation.

  • Or ignore namespaces, which is easy starting from XPath 2.0 by using the "wildcard namespace"

    /*:Envelope/*:Header/*:Security/*:Timestamp
    

    For XPath 1.0, you cannot do this, you will have to select all elements and check for their name:

    /*[local-name() = "Envelope"]/*[local-name() = "Header"]/*[local-name() = "Security"]/*[local-name() = "Timestamp"]
    

    Generally, ignoring namespaces should be regarded bad practise, and especially in XPath 1.0 leads to horrible to read and probably slower queries.

于 2013-06-21T08:20:20.693 回答