Unable to read xml with namespace prefix using DOM parser

后端 未结 4 1848
旧巷少年郎
旧巷少年郎 2020-12-19 05:04

This is the input XML:


   
   

        
4条回答
  •  我在风中等你
    2020-12-19 05:40

    Try to use XPath expression. See sample code below.

    Document doc = dBuilder.parse(new ByteArrayInputStream(responseXML.getBytes()));
    doc.getDocumentElement().normalize();
    XPath xPath =  XPathFactory.newInstance().newXPath();
    
    String expression = "/ns6:ReadPersonReturn/ns6:object/ns3:Person/ns3:Phone/ns3:item";
    NodeList nodes = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET);
    Element secondNode = null;
    if(nodes != null && nodes.getLength() > 0){
        secondNode = (Element) leadCloudPingRecordNodes.item(i);
    }
    

提交回复
热议问题