无法使用XPATH

时间:2015-08-28 10:37:48

标签: xml xpath

我有以下xml:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP:Body>
      <performJob loadfromcache="yes">
         <jobName>PQIssueDetails</jobName>
         <whiteboard>
            <PQ>
               <hostAddress>21212</hostAddress>
               <hostPort>12955</hostPort>
               <timeout>120000</timeout>
               <trace>0</trace>
               <readable>N</readable>
               <userID>2121</userID>
               <password>XXX@1</password>
               <currentDate>8/28/2015 10:31 AM</currentDate>
               <AWD10SP7_1orhigher>Y</AWD10SP7_1orhigher> 
               <METHOD>GET</METHOD>
               <eao>08272015</eao>
               <storedProcedure id="PQISSUEDETAIL">
                  <parameter id="P_CRDATTIM">
                     <value>2015-08-25-01.40.19.219580</value>
                     <dataType>string</dataType>
                  </parameter>
                  <parameter id="P_RECORDCD">
                     <value>T</value>
                     <dataType>string</dataType>
                  </parameter>
                  <parameter id="P_CRNODE">
                     <value>01</value>
                     <dataType>string</dataType>
                  </parameter>
               </storedProcedure>
            </PQ>
         </whiteboard>
         <requestNodeName>.</requestNodeName>
         <responseNodeName>//PQ</responseNodeName>
         <jobDB>
            <name>PQCustomerService</name>
            <userID>sa</userID>
            <password>password</password>
         </jobDB>
      </performJob>
   </SOAP:Body>
</SOAP:Envelope>

我想只获得<value>标记下第一个参数的<storedProcedure>值。

我正在尝试使用以下XPATH,但它无法正常工作

//PQ/storedProcedure/parameter[1]/@value

我认为在使用XPATH时我做错了什么你可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

值不是属性而是标记,因此请使用xpath

//PQ/storedProcedure/parameter[1]/value