Only one XML declaration is permitted in well-formed XML, and it must be at the top if anywhere.
Must be at the top
See the definition of document
in the Well-Formed XML Documents section of the XML Recommendation:
[1] document ::= prolog element Misc*
Then check prolog
:
[22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
And then XMLDecl
:
[23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
So, we see that the EBNF permits an XML declaration at the top of the document.
Only one
Processing instructions...
[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
[17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
...in general may occur elsewhere, but a second XML declaration is precluded by virtue of the definition of PITarget
and this statement:
The target names " XML ", " xml ", and so on are reserved for
standardization in this or future versions of this specification.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…