0

For example, let us say we have the following schema (listed in http://www.w3.org/TR/xmlschema-0/#NS)

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:po="http://www.example.com/PO1" targetNamespace="http://www.example.com/PO1" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <element name="purchaseOrder" type="po:PurchaseOrderType"/> <element name="comment" type="string"/> <complexType name="PurchaseOrderType"> <sequence> <element name="shipTo" type="po:USAddress"/> <element name="billTo" type="po:USAddress"/> <element ref="po:comment" minOccurs="0"/> <!-- etc. --> </sequence> <!-- etc. --> </complexType> <complexType name="USAddress"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <!-- etc. --> </sequence> </complexType> <!-- etc. --> </schema> 

Can you explain what the purpose of each of the attributes in the "schema" node mean? I have been trying to wrap my head around it, but I don't get it. Please correct me if I am wrong:

I assume xmlns="http://www.w3.org/2001/XMLSchema" refers to elements & attributes that have no prefix.

xmlns:po="http://www.example.com/PO1" seems like it means that anything prefixed with po, refers to this url (example.com/p01).

I don't understand what targetNamespace is for. I also don't understand what qualified or unqualified means.

1 Answer 1

1

This is a bit of a terminology minefield, but essentially, xmlns="http://www.w3.org/2001/XMLSchema" and xmlns:po="http://www.example.com/PO1" are there to declare namespaces for the schema document itself. Remember, an XML Schema is just an XML document, and it needs to declare the namespaces it uses just like any other XML document.

targetNamespace is used to define the namespace of the schema's instance documents, i.e. the documents which will conform to your schema. Such documents would declare their namespace to be http://www.example.com/PO1, with whatever prefix they choose e.g. they could use xmlns="http://www.example.com/PO1" or xmlns:po="http://www.example.com/PO1"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.