Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is on the first line of an XML document?

Tags:

xml

xsd

So before we write the XML Schema, a lot of tutorials use this:

 <?xml version='1.0'?>

or

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

My question is, what is this part for? What is that website specifically and why do we use it? Are there other methods to do this?

If it helps, I am doing this to convert an excel worksheet into XML.

like image 290
J.H Avatar asked Sep 03 '25 13:09

J.H


2 Answers

XML Declaration

<?xml version='1.0'?> is an XML declaration and is not particular to XSDs but to XML documents in general.

[Definition: XML documents should begin with an XML declaration which specifies the version of XML being used.]

As an XSD is an XML document, it may also have an XML declaration.

Here is the BNF of an XML declaration (XMLDecl) with links to the definitions of its constituent parts:

XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

Note: Only one XML declaration is permitted in well-formed XML, and it must be at the top if anywhere. If you violate this requirement, you'll see an error such as

The processing instruction target matching "[xX][mM][lL]" is not allowed.

and you'll have to fix the problem before your XML will be well-formed.


XML Schema Instance Namespace

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is a namespace declaration for the special XML Schema instance namespace. As a namespace URI, its purpose is to facilitate control of grouping of component name. An XML namespace URI does not have to be retrievable.

See also

  • What are XML namespaces for regarding the purpose of namespaces in general.
  • Schema-Related Markup in Documents Being Validated for XSD attributes that use xsi in particular. (xsi:type, xsi:nil, xsi:schemaLocation, and xsi:noNamespaceSchemaLocation)
like image 50
kjhughes Avatar answered Sep 05 '25 15:09

kjhughes


XML declaration. See https://www.w3.org/TR/2006/REC-xml-20060816/#sec-prolog-dtd for more information.

like image 39
keshlam Avatar answered Sep 05 '25 17:09

keshlam