Search in sources :

Example 16 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class DomConverterTest method testDomConverterToList.

public void testDomConverterToList() throws Exception {
    Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<foo><hello>Hello World</hello><bye>Bye Camel</bye></foo>");
    List<?> list = DomConverter.toList(document.getElementsByTagName("foo"));
    assertEquals(1, list.size());
    NodeList nl = assertIsInstanceOf(NodeList.class, list.get(0));
    List<?> sub = DomConverter.toList(nl);
    assertEquals(2, sub.size());
    assertEquals("<hello>Hello World</hello>", new DomConverter().toString((NodeList) sub.get(0), null));
    assertEquals("<bye>Bye Camel</bye>", new DomConverter().toString((NodeList) sub.get(1), null));
}
Also used : NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 17 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class XPathFunctionTest method testSetXpathProperty.

public void testSetXpathProperty() throws Exception {
    String body = "<soapenv:Body xmlns:ns=\"http://myNamesapce\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<ns:Addresses> <Address>address1</Address>" + " <Address>address2</Address> <Address>address3</Address>" + " <Address>address4</Address> </ns:Addresses> </soapenv:Body>";
    end.reset();
    end.expectedMessageCount(1);
    template.sendBody("direct:setProperty", body);
    assertMockEndpointsSatisfied();
    Exchange exchange = end.getExchanges().get(0);
    NodeList nodeList = exchange.getProperty("Addresses", NodeList.class);
    assertNotNull("The node list should not be null", nodeList);
}
Also used : Exchange(org.apache.camel.Exchange) NodeList(org.w3c.dom.NodeList)

Example 18 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class XmlLineNumberParserTest method testParseCamelContextForceNamespace.

public void testParseCamelContextForceNamespace() throws Exception {
    FileInputStream fis = new FileInputStream("src/test/resources/org/apache/camel/util/camel-context.xml");
    Document dom = XmlLineNumberParser.parseXml(fis, null, "camelContext", "http://camel.apache.org/schema/spring");
    assertNotNull(dom);
    NodeList list = dom.getElementsByTagName("camelContext");
    assertEquals(1, list.getLength());
    Node node = list.item(0);
    String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
    String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
    String ns = node.getNamespaceURI();
    assertEquals("http://camel.apache.org/schema/spring", ns);
    assertEquals("28", lineNumber);
    assertEquals("46", lineNumberEnd);
    // and there are two routes
    list = dom.getElementsByTagName("route");
    assertEquals(2, list.getLength());
    Node node1 = list.item(0);
    Node node2 = list.item(1);
    String lineNumber1 = (String) node1.getUserData(XmlLineNumberParser.LINE_NUMBER);
    String lineNumberEnd1 = (String) node1.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
    assertEquals("30", lineNumber1);
    assertEquals("36", lineNumberEnd1);
    String lineNumber2 = (String) node2.getUserData(XmlLineNumberParser.LINE_NUMBER);
    String lineNumberEnd2 = (String) node2.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
    assertEquals("38", lineNumber2);
    assertEquals("44", lineNumberEnd2);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream)

Example 19 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class XmlLineNumberParserTest method testParse.

public void testParse() throws Exception {
    FileInputStream fis = new FileInputStream("src/test/resources/org/apache/camel/util/camel-context.xml");
    Document dom = XmlLineNumberParser.parseXml(fis);
    assertNotNull(dom);
    NodeList list = dom.getElementsByTagName("beans");
    assertEquals(1, list.getLength());
    Node node = list.item(0);
    String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
    String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
    assertEquals("23", lineNumber);
    assertEquals("48", lineNumberEnd);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream)

Example 20 with NodeList

use of org.w3c.dom.NodeList in project groovy by apache.

the class DOMCategory method breadthFirst.

public static NodeList breadthFirst(Element self) {
    List<NodeList> result = new ArrayList<NodeList>();
    NodeList thisLevel = createNodeList(self);
    while (thisLevel.getLength() > 0) {
        result.add(thisLevel);
        thisLevel = getNextLevel(thisLevel);
    }
    return new NodeListsHolder(result);
}
Also used : NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList)

Aggregations

NodeList (org.w3c.dom.NodeList)1806 Node (org.w3c.dom.Node)1059 Element (org.w3c.dom.Element)902 Document (org.w3c.dom.Document)636 ArrayList (java.util.ArrayList)314 DocumentBuilder (javax.xml.parsers.DocumentBuilder)268 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)208 IOException (java.io.IOException)183 NamedNodeMap (org.w3c.dom.NamedNodeMap)144 InputSource (org.xml.sax.InputSource)131 HashMap (java.util.HashMap)121 Test (org.junit.Test)117 SAXException (org.xml.sax.SAXException)117 StringReader (java.io.StringReader)106 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)100 XPath (javax.xml.xpath.XPath)99 Attr (org.w3c.dom.Attr)80 XPathExpressionException (javax.xml.xpath.XPathExpressionException)76 File (java.io.File)64 HashSet (java.util.HashSet)59