Java XPath特定元素搜索

Java XPath特定元素搜索,java,xpath,Java,Xpath,我试图使用XPath获取下面XML字符串中的sessionUID和enewstokXML元素,但无法确定XPath表达式。节点列表是空的。查看响应XML,我认为不需要为XPath声明名称空间。有什么建议吗 响应XML: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="ht

我试图使用XPath获取下面XML字符串中的sessionUID和enewstokXML元素,但无法确定XPath表达式。节点列表是空的。查看响应XML,我认为不需要为XPath声明名称空间。有什么建议吗

响应XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <wsu:Timestamp xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
         <wsu:Created>2011-08-12T03:07:19Z</wsu:Created>
         <wsu:Expires>2011-08-12T03:12:19Z</wsu:Expires>
      </wsu:Timestamp>
   </soap:Header>
   <soap:Body>
      <LoginResponse xmlns="http://c1.net.corbis.com/">
         <**sessionUID**>{f7be62e6-0bf5-44a7-bf77-5ab2bf307a23}</sessionUID>
         <**eNewSTok**>JdKVwENgF7SbdBX2x4R+BTA/WiJatMpCJvFckhNtzbx+WZ8OqmSu+fzD36XL4irDsbp69O8YioZl6iYcwrui6NWo6dBh7YCf18A4c4Ry3nFWLpBkUt35sQmBcON1kD79+1lvdJNZrzKOQIDo3Qs/ogb95aVrp7TAgjIkugti3Q0=</eNewSTok>
         <securityTokenXML><![CDATA[<SecurityToken><ActualMemberUID Scope="Public" Type="Guid" Value="{b7fde077-c13e-40a7-aae9-f18c5a66f3e1}"/><EffectiveMemberUID Scope="Public" Type="Guid" Value="{b7fde077-c13e-40a7-aae9-f18c5a66f3e1}"/><RoleID Scope="Public" Type="Long" Value="49"/><CountryCode Scope="Public" Type="String" Value="US"/><RegionCode Scope="Public" Type="String" Value="CA"/><LanguageID Scope="Public" Type="Long" Value="100958"/><OnyxSessionID Scope="Public" Type="String" Value=""/></SecurityToken>]]></securityTokenXML>
      </LoginResponse>
   </soap:Body>
</soap:Envelope>

2011-08-12T03:07:19Z
2011-08-12T03:12:19Z
{f7be62e6-0bf5-44a7-bf77-5ab2bf307a23}
JdKVwENgF7SbdBX2x4R+BTA/WiJatMpCJvFckhNtzbx+WZ8OqmSu+FZD36XL4IRDSBP69O8YIOZL6IYCWRUI6NWO6DBH7YCF18A4Cry3NWLpbKUT35SQMBCON1KD79+1LVDJNZRZKOQ3QS/ogb95aVrp7TAgjIkugti3Q0=
]]>
Java代码:

String responseXML = StringEscapeUtils.unescapeXml(sb.toString());
        InputSource source = new InputSource(new StringReader(responseXML));
        XPath xPath = XPathFactory.newInstance().newXPath();
        NodeList list = (NodeList)xPath.evaluate("(//sessionUID)|(//eNewSTok)", source, XPathConstants.NODESET);
        for (int i = 0; i < list.getLength(); i++)
        {
            System.out.println(list.item(i).getTextContent());
        }
String responseXML=StringEscapeUtils.unescapeXml(sb.toString());
InputSource source=新的InputSource(新的StringReader(responseXML));
XPath=XPathFactory.newInstance().newXPath();
NodeList list=(NodeList)xPath.evaluate((//sessionUID)|(//eNewSTok)”,源代码,XPathConstants.NODESET);
对于(int i=0;i
您需要为XPathFactory指定名称空间。看