2016-11-30 87 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 

的要求。