use of org.w3c.dom.Document in project camel by apache.
the class XmlConverterTest method testToInputStreamFromDocument.
public void testToInputStreamFromDocument() throws Exception {
XmlConverter conv = new XmlConverter();
Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
InputStream is = conv.toInputStream(doc, null);
assertNotNull(is);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlConverterTest method testToStringWithDocumentSourceOutputProperties.
public void testToStringWithDocumentSourceOutputProperties() throws Exception {
XmlConverter conv = new XmlConverter();
Document document = conv.createDocument();
Element foo = document.createElement("foo");
foo.setTextContent("bar");
document.appendChild(foo);
Properties properties = new Properties();
properties.put(OutputKeys.ENCODING, "ISO-8859-1");
String out = conv.toStringFromDocument(document, properties);
assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?><foo>bar</foo>", out);
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlConverterTest method testToDomElementFromElementNode.
public void testToDomElementFromElementNode() throws Exception {
XmlConverter conv = new XmlConverter();
Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
Element out = conv.toDOMElement(doc.getDocumentElement());
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
use of org.w3c.dom.Document in project camel by apache.
the class DomConverterTest method testDomConverterToInteger.
public void testDomConverterToInteger() throws Exception {
Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>47</hello>");
Integer number = DomConverter.toInteger(document.getChildNodes());
assertEquals(47, number.intValue());
}
use of org.w3c.dom.Document 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));
}
Aggregations