Cant figure out why XMLUtils.outputDOM is not outputing anything
import org.apache.xml.security.utils.XMLUtils;
DocumentBuilderFactory dbf= DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
InputSource is = new InputSource(new StringReader("<EDoc></EDoc>"));
Document doc = dbf.newDocumentBuilder().parse(is);
Element root = doc.getDocumentElement();
System.out.println(root);
OutputStream os = new FileOutputStream("out_xs.xml");
XMLUtils.outputDOM(root, os, true);
System.out.println(XMLUtils.getFullTextChildrenFromElement(root));
Output is:
[EDoc: null]
(empty string)
out_xs.xml:
<?xml version="1.0" encoding="UTF-8"?>
I can get the root element OK, but file is generated with xml definition only as true is provided. What is going on? I am using same function in other place where it works after library uses Document, so I suspect Document should be notified to commit changes? Cant find any information using search
OutputStream?out_xs.xmlfile not getting XML, but you don't show us what is actually in the file. Instead you show us thatgetFullTextChildrenFromElement(root)returns an empty string, which has nothing whatsoever to do withoutputDOM(root, os, true), and blank output is expected, since there are no text nodes in the XML, so not sure why that code is even there, except it is confusing the issue. Please clean up the question, to clarify it.