0

如何使用 xpath 从下面的肥皂消息中检索以下节点的值:Serverid & id。我希望根据节点名称进行搜索,然后获取节点值。

<soapenv:Envelope xmlns:dest="http://www.testsrv.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <dest:Security>
            <dest:ticket secuid ="21020303"/>
        </dest:Security>
    </soapenv:Header>
    <soapenv:Body>
        <TransReq>
            <Sender>
                <ServerOne>testserver</ServerOne>
                **<Serverid>led189</Serverid>**
            </Sender>
            <Form>
                **<id>2EB</id>**
                <token>8EB9</token>
            </Form>
        </TransReq>
    </soapenv:Body>
</soapenv:Envelope>

沿着这行代码......

SOAPBody requestBody = message.getSOAPBody();
XPath xpath = XPathFactory.newInstance().newXPath(); 
Node resultNode = (Node) xpath.evaluate("/Serverid", message.getSOAPBody(),XPathConstants.NODE); // doesnt look right but just an idea of what i am trying to do ...

提前致谢

4

0 回答 0