org.w3c.dom.Document conversion to java.io.InputStream not read properly by SAXParser -
I use the following code to parse a org.w3c.dom.Document
I am javax.xml.parsers.SAXParser
.
Try {// --- prepare our suction parser --- SACPERSER Factor factory = SAXParserFactory.newInstance (); Factory.setValidating (true); SAXParser Parser = Factory NASAXpers (); // parser.pars (xmlfile, xmldidate); / * Does not validate unsaved changes / / / --- Create a stream our already predicted XML document --- BitReon OutputStream Output Stream = New Bytereon OutputStream (); Source xmlSource = new DOMSource (xmlDocument); Results Output Target = New Stream Result (OutputStream); Transformerfacture.New Instance (). New Transformer (). Transform (XMLSOS, output tag); // --- XMLDCasting --- Parser.pars (new bytereinputstream (outputstream.Tibetre ()), XMLWidator; } Grip (parser configuration exception | SAXException | TransformerException | TransformForm configuration error | IOException e) {E.PintstacksTrace (); }
I get an error message when the document is parsed
Line 1: Document root element 'MyRootName' to DOCTYPE root 'null' Should match. / Code>
If I simply parse
xmlFile
which is based on xmlDocument
, then everything works fine.
I have ensured that xmldocument is initial and valid, I have tried to pass through xmlDocument.getDocumentElement ()
to DOMSource
, which I Also, I am sure that what I am hoping to do it (i.e. the root node of the document whose exact name is)
why not javax.xml.parsers.SAXParser
Java reading .io.InputStream
is the same way it is reading from xmlfile` file system?
Edit
Related Questions (I have tried all of these solutions
So the problem was not with T. It was with parser
, it was with the transformer
, which is & Lt ;! DOCTYPE ... & gt;
was extracting the line to solve this problem, just set up a Transformer property, then this DTD file is also included.
// --- Creating a Transformer and Our Document in an InputStream TRANSFORMER TRANSFORMER = TransformerFactory.newInstance () .newTransformer (); // DOCTYPE tags out of transformer strips by default so that we will add our DTD file declaration transformer.setOutputProperty again (OutputKeys.DOCTYPE_SYSTEM, xmlFile.getParent ( ) + "\\" + xmlDocument.getDoctype (). GetSystemId ()); Transformer. Transform (xmlSource, Output Tag);
You simply cross the name of the DTD file, Parser space was started from the program but searching for it, as it is, file DTD It is advisable to specify a direct path for I have up.
Comments
Post a Comment