Re: [xml] Degenerate case



On Tue, 2019-09-17 at 00:47 -0400, Webb Scales wrote:
Would a file containing just an XML comment, e.g.,

<!-- My comment. -->


be an acceptable input to LibXML2?

Let's look at  the specification of XML,
https://www.w3.org/TR/REC-xml/

We see in section 2.1,
[[
 [Definition: A textual object is a well-formed XML document if:]

    Taken as a whole, it matches the production labeled document.

    It meets all the well-formedness constraints given in this
specification.

    Each of the parsed entities which is referenced directly or
indirectly within the document is well-formed.
]]

So we need our input to match Document.

The immediately following text in the spec has,
[[

Document
[1]     document           ::=          prolog element Misc*
]]

If you follow these you find "element" means we need exactly one top-
level element, <foo>...</foo>, and your example has a comment but no
element. So, it is not well-formed.

You will find it helpful to become moer familiar with the grammar in
the XML specification.

Best,

Liam


-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]