0

我正在尝试从这些 xml 中获取数据:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.alternative.thy.com/" xmlns:req="http://www.thy.com/ws/requestHeader" xmlns:ns="http://www.opentravel.org/OTA/2003/05">
<soapenv:Header/>
<soapenv:Body>
      <ser:GS>
         <!--Optional:-->
         <requestHeader>
            <!--Optional:-->
            <req:clientCode>KL7MU</req:clientCode>
            <!--Optional:-->
            <req:clientUsername>BLABLA</req:clientUsername>
         </requestHeader>
      </ser:GS>
   </soapenv:Body>

为了获得客户用户名,我写了

        SOAPMessage message = context.getMessage();

        OutputStream os = new ByteArrayOutputStream();

        message.writeTo(os);

        String xpath = "////requestHeader/req:clientUsername";
        XPath xPath = XPathFactory.newInstance().newXPath();
        String sad = xPath.evaluate(xpath, new InputSource(
                new StringReader(os.toString())));

但它返回:javax.xml.xpath.XPathExpressionException。我认为我的失败原因是 xpath 语句 ////requestHeader/req:clientUsername 是正确的语句吗?

4

1 回答 1

0

尝试 :

soapenv//ser:GS//requestHeader//req:clientUsername
于 2013-09-24T17:57:50.907 回答