Is this one a valid XML instance? It has nothing between the the XML declaration and the root node.
<?xml version="1.0" encoding="UTF-8"?><data></data>
I could not find the right place in the XML specification myself and hope that somebody will help me...
XML doesn't require "lines", it's a nested storage structure and any additional newlines and whitespace will be ignored, and they just take up additional storage space.
XML declaration contains details that prepare an XML processor to parse the XML document. It is optional, but when used, it must appear in the first line of the XML document.
The first line of an XML document should be a declaration that this is an XML document, including the version of XML being used.
The spec (see 2.8 Prolog and Document Type Declaration) does not require (but does allow) a newline to follow the XML Declaration.
Formally this is written as:
[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
...[22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
...[27] Misc ::= Comment | PI | S
As you can see in [22] prolog
the XML Declaration is optional (see the questionark after the symbol) and zero, one or more (see the star) Misc
can follow which are: Comments, other Processing Instructions (PI
) or Whitespace (S
). Whitespace includes the newline.
Because Misc
is optional here, there can but need not follow a newline after the declaration.
New lines or so are not part of the spec. When you, for example, write a XML Document with the XMLOutputter Class (in Java), you get a file without newlines. Newlines are for humans.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With