2016-11-30 58 views
0

我試圖爲ID爲tblXDAP-txtfXdapType - 1的單個「表單」選擇元素「值」的子文本。xPath幫助 - 選擇同胞

這裏是我的XML

<form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapType--1</ID> 
    <label xsi:type="soapenc:string">XDAP Type</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string">Win7 x64 Developer</value> 
</form> 
<form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapUser--1</ID> 
    <label xsi:type="soapenc:string">User</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string"/> 
</form> 
<form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapType--2</ID> 
    <label xsi:type="soapenc:string">XDAP Type</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string">Win7 x86 Standard</value> 
</form> 

我使用XPath //*[local-name()='form'][*[local-name()='ID'][starts-with(., 'tblXDAP-txtfXdapType--1')]]的樣本,但我無法選擇該查詢的值。在我的例子,我想選擇值「X64 Win7的開發」

回答

0

假設XML片段與一個根元素良好的XML的一部分,

<?xml version="1.0" encoding="UTF-8"?> 
<r xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapType--1</ID> 
    <label xsi:type="soapenc:string">XDAP Type</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string">Win7 x64 Developer</value> 
    </form> 
    <form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapUser--1</ID> 
    <label xsi:type="soapenc:string">User</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string"/> 
    </form> 
    <form xsi:type="ns1:FormElement"> 
    <ID xsi:type="soapenc:string">tblXDAP-txtfXdapType--2</ID> 
    <label xsi:type="soapenc:string">XDAP Type</label> 
    <labelValue xsi:nil="true" xsi:type="soapenc:string"/> 
    <type xsi:type="xsd:int">0</type> 
    <value xsi:type="soapenc:string">Win7 x86 Standard</value> 
    </form> 
</r> 

那麼這XPath的,

string(//form[ID = 'tblXDAP-txtfXdapType--1']/value) 

將選擇的formvalue元素的字符串值作爲指定,

Win7 x64 Developer 

的要求。