Question

At the top of the XML files I'm studying, I see at the beginning:

<selfModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="../../dtd/selfmodel.xsd">

then after that it's the actual meat of the XML:

  <plan id = "offer" default="true">
     <description>Automatically generated from ACELandic specification</description>
        <states> .. etc

What is the purpose of the xmlns:xsi= and xsi:noNamespaceSchemaLocation stuff? Does it get searched/verified online when the file is compiled? That's what I assume by the URL www.w3.org/2001/XMLSchema-instance but that seems very inefficienmt

Was it helpful?

Solution

That's not a header. It's just the root node of the document.

The "xmlns:xsi" attribute that you see in that element is a namespace declaration. Namespaces need to be declared before they are used. So they are often declared all the way at the top of the document. It is only necessary to declare them before they are used.

Although namespace names (the values in the namespace attributes) are often in the form of a URL, they are not necessarily the location of a resource on the Internet. They are simply unique names. In particular, they will always be in the form of a URI, a syntax which is a superset of a "URL", but which can only be used as a unique identifier, not as the location of a resource on the Internet.

The URIs given as values of "xsi:schemaLocation" and "xsi:noNamespaceSchemaLocation" are the locations of schemas which can be used to validate the document. They are not necessary, but they are nice to have. Not all XML parsers will pay attention to them. In particular, you may not be doing XML validation, or may not wish to use the Internet during validation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top