Example usage for org.w3c.dom Document getOwnerDocument

List of usage examples for org.w3c.dom Document getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Document getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParserTest.java

@Test
public void testNamespaceAwareXpathResolveWithPreparser() throws Exception {
    NamespaceTestSuite testSuite = new NamespaceTestSuite().invoke();
    DocumentBuilderFactory domFactory = testSuite.getDomFactory();
    String xmlString = testSuite.getXmlString();
    XPath xPath = testSuite.getxPath();
    Map<String, String> namespaces = testSuite.getNamespaces();

    DocumentBuilder builder = domFactory.newDocumentBuilder();
    // Document document = builder.parse(IOUtils.toInputStream(xmlString, Utils.UTF8));
    XMLFromBinDataPreParser xmlFromBinDataPreParser = new XMLFromBinDataPreParser();
    Document document = xmlFromBinDataPreParser.preParse(xmlString);

    NamespaceMap nsContext = new NamespaceMap();
    xPath.setNamespaceContext(nsContext);

    nsContext.addPrefixUriMappings(namespaces);

    Document tDoc = document.getOwnerDocument();
    Element docElem = tDoc == null ? null : tDoc.getDocumentElement();
    if (tDoc == null || StringUtils.isEmpty(tDoc.getNamespaceURI())) {
        document = builder//from   w  w w. j a  v a  2s  .  c  o  m
                .parse(new ReaderInputStream(new StringReader(Utils.documentToString(document)), Utils.UTF8));
    }

    NamespaceMap documentNamespaces = new NamespaceMap();
    StreamsXMLUtils.resolveDocumentNamespaces(document, documentNamespaces, false);

    String evaluate = xPath.compile("/soapenv:Envelope/soapenv:Header/ch:TSYSprofileInq/ch:clientData")
            .evaluate(document);
    assertEquals("xxxxxx-343e-46af-86aa-634a3688cf30", evaluate);
    evaluate = xPath.compile("/Envelope/Header/TSYSprofileInq/clientData").evaluate(document);
    assertEquals("", evaluate);
}