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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations