module

Noir::XmlComments

XML comments, removed before anything reads the document.

libxml2 copies the comment text parsed so far into every error it raises inside a comment, and -- inside a comment is an error. A comment holding many --, or a run of unterminated <!-- (each one nests in the last), made XML.parse quadratic: a 1.6 MB web.xml cost over 20 seconds of CPU. No analyzer reads comment nodes, so they are dropped in one linear pass before libxml2 sees them.

Class methods

parse(content : String, options : XML::ParserOptions = XML::ParserOptions.default) : XML::Node

XML.parse on the comment-free document.

Source
strip(content : String) : String

content with each <!-- ... --> replaced by the newlines it spanned, so line numbers still match the source. An unterminated <!-- runs to the end of the document, as an XML parser reads it. CDATA sections pass through untouched: a <!-- inside one is text, not a comment. So do processing instructions and the DOCTYPE (an entity value may hold a <!--); a comment inside the internal subset is left for libxml2.

Source