0

如何使用 Java XPath 从地址名称为“BILL_TO”(如果有)的addressinformation(在本例中为 999123 )获取 UUID?

这是我的 XML:

    <Company>
        <Name>My Company</Name>
        <LastName>Smith</LastName>
        <FirstName>Jim</FirstName>
        <street>123 Main Street</street>
        <AddressInformation>
                <UUID>543233<UUID>
            <Address>
                <UUID>223223</UUID>
                <AddressID>
                    <AddressName>Default</AddressName>
                </AddressID>
            </Address>
        </AddressInformation>
        <AddressInformation>
                <UUID>999123<UUID>
            <Address>
                <UUID>443211</UUID>
                <AddressID>
                    <AddressName>BILL_TO</AddressName>
                </AddressID>
            </Address>
        </AddressInformation>
        <city>Mytown</city>
        <state>NY</state>
        <zip>11234</zip>
</Company>
4

1 回答 1

3

好的,首先你的 XML 格式不正确,所以我为你修复了它

 <Company>
    <Name>My Company</Name>
    <LastName>Smith</LastName>
    <FirstName>Jim</FirstName>
    <street>123 Main Street</street>
    <AddressInformation>
            <UUID>543233</UUID>
        <Address>
            <UUID>223223</UUID>
            <AddressID>
                <AddressName>Default</AddressName>
            </AddressID>
        </Address>
    </AddressInformation>
    <AddressInformation>
            <UUID>999123</UUID>
        <Address>
            <UUID>443211</UUID>
            <AddressID>
                <AddressName>BILL_TO</AddressName>
            </AddressID>
        </Address>
    </AddressInformation>
    <city>Mytown</city>
    <state>NY</state>
    <zip>11234</zip>
</Company>

那么这是应该为您解决问题的xpath:

//Company/AddressInformation[Address/AddressID/AddressName='BILL_TO']/UUID
于 2013-03-11T21:38:24.137 回答