Search in sources :

Example 46 with Document

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

the class DomConverterTest method testDomConverterToBytes.

public void testDomConverterToBytes() throws Exception {
    Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
    byte[] bytes = new DomConverter().toByteArray(document.getChildNodes(), null);
    assertTrue("Should be equal", ObjectHelper.equalByteArray("<hello>world!</hello>".getBytes("UTF-8"), bytes));
}
Also used : Document(org.w3c.dom.Document)

Example 47 with Document

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

the class DomConverterTest method testDomConverterToInputStream.

public void testDomConverterToInputStream() throws Exception {
    Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
    InputStream is = new DomConverter().toInputStream(document.getChildNodes(), null);
    assertEquals("<hello>world!</hello>", context.getTypeConverter().convertTo(String.class, is));
}
Also used : InputStream(java.io.InputStream) Document(org.w3c.dom.Document)

Example 48 with Document

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

the class JaxpTest method testConvertToDocument.

public void testConvertToDocument() throws Exception {
    Document document = converter.convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>");
    assertNotNull(document);
    LOG.debug("Found document: " + document);
    // lets now convert back again
    String text = converter.convertTo(String.class, document);
    // The preamble changes a little under Java 1.6 it adds a
    // standalone="no" attribute.
    assertTrue("Converted to String: " + text, text.endsWith("<hello>world!</hello>"));
}
Also used : Document(org.w3c.dom.Document)

Example 49 with Document

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

the class XmlConverterTest method testToDocumentFromInputStream.

public void testToDocumentFromInputStream() throws Exception {
    XmlConverter conv = new XmlConverter();
    InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
    Document out = conv.toDOMDocument(is);
    assertNotNull(out);
    assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
Also used : InputStream(java.io.InputStream) Document(org.w3c.dom.Document)

Example 50 with Document

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

the class XmlConverterTest method testToDocumentFromFile.

public void testToDocumentFromFile() throws Exception {
    XmlConverter conv = new XmlConverter();
    File file = new File("src/test/resources/org/apache/camel/converter/stream/test.xml");
    Document out = conv.toDOMDocument(file);
    assertNotNull(out);
    String s = context.getTypeConverter().convertTo(String.class, out);
    assertTrue(s.contains("<firstName>James</firstName>"));
}
Also used : Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

Document (org.w3c.dom.Document)2446 Element (org.w3c.dom.Element)990 DocumentBuilder (javax.xml.parsers.DocumentBuilder)719 NodeList (org.w3c.dom.NodeList)648 Node (org.w3c.dom.Node)545 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)528 IOException (java.io.IOException)425 SAXException (org.xml.sax.SAXException)301 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)299 InputSource (org.xml.sax.InputSource)250 Test (org.junit.Test)233 File (java.io.File)190 StringReader (java.io.StringReader)182 ArrayList (java.util.ArrayList)174 InputStream (java.io.InputStream)167 DOMSource (javax.xml.transform.dom.DOMSource)161 ByteArrayInputStream (java.io.ByteArrayInputStream)154 Attr (org.w3c.dom.Attr)134 DOMException (org.w3c.dom.DOMException)129 XPath (javax.xml.xpath.XPath)107