otnj2ee
01-12-2008, 01:17 AM
I saw some coding like this:
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding","UTF-8");
t.transform(new DOMSource(doc),new StreamResult(baos)); String xmlString = new String(baos.toByteArray(), "utf8");
My questions are:
1) Does the doc (Document)
contains the such header as:
<?xml version="1.0" ?>
2) Must the doc object host an XML string, or it can contain any type string(i.e., not necessarily an XML string)?
3) What is the purpose of using the transformer to transform the doc as:
t.transform(new DOMSource(*doc*),new StreamResult(*baos*));
4) Does the Transformer add the header <?xml version="1.0" ?> to the baos object?
Thanks
Scott
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
t.setOutputProperty("encoding","UTF-8");
t.transform(new DOMSource(doc),new StreamResult(baos)); String xmlString = new String(baos.toByteArray(), "utf8");
My questions are:
1) Does the doc (Document)
contains the such header as:
<?xml version="1.0" ?>
2) Must the doc object host an XML string, or it can contain any type string(i.e., not necessarily an XML string)?
3) What is the purpose of using the transformer to transform the doc as:
t.transform(new DOMSource(*doc*),new StreamResult(*baos*));
4) Does the Transformer add the header <?xml version="1.0" ?> to the baos object?
Thanks
Scott