elharo opened a new pull request, #133: URL: https://github.com/apache/xerces-j/pull/133
Fixes https://issues.apache.org/jira/browse/XERCESJ-150 ## Problem `XMLSerializer` accumulates comments and processing instructions that occur before the root element and emits them after the DOCTYPE. XML permits these to appear before the DOCTYPE, and their position should be preserved. For example, this sequence: ```java serializer.startDocument(); serializer.processingInstruction("foo", "bar"); serializer.startDTD("foo", "bar", "baz"); ``` previously placed `<?foo bar?>` after `<!DOCTYPE ...>`. It is now emitted before the DOCTYPE. The same issue affected comments and DOM-based serialization. ## Fix - Track how many pre-root comments/PIs were seen before the DOCTYPE (via `startDTD` and the DOM `DocumentType` node). - Emit that prefix before the DOCTYPE in `XMLSerializer` and `HTMLSerializer`, then emit the remainder afterwards. - Process `DocumentType` nodes in document order when serializing a DOM `Document`, so comments/PIs before the doctype are distinguished from those after it. ## Tests Added `dom.serialize.TestPreRootSerialization`, covering both the SAX and DOM serialization paths. Four of its eight tests fail on the unmodified tree and all pass with this change. `ant test` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
