Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

difference between two schema

1 view
Skip to first unread message

thierry

unread,
Nov 8, 2009, 3:54:59 PM11/8/09
to
Hello,

I would like to understand the difference between FIRST

<?xml version="1.0" encoding="iso-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://domaine.tld"
xmlns="http://domaine.tld">

<xsd:element name="serveur" type="xsd:string" />
<xsd:element name="definition">
<xsd:complexType>
<xsd:all>
<xsd:element ref="serveur" minOccurs
="1" maxOccurs ="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>

which validate

<?xml version="1.0" encoding="utf-8"?>
<definition xmlns="http://domaine.tld">
<serveur>serveur1</serveur>
</definition>

AND SECOND

<?xml version="1.0" encoding="iso-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://domaine.tld"
xmlns="http://domaine.tld">

<xsd:element name="definition">
<xsd:complexType>
<xsd:all>
<xsd:element name="serveur" minOccurs
="1" maxOccurs ="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>

which validate

<?xml version="1.0" encoding="utf-8"?>
<definition xmlns="http://domaine.tld">
<serveur xmlns="">anyType</serveur>
</definition>

The difference is the xmlns attribute in the serveur tag of the second
xml file.

thank you in advance

thierry

Martin Honnen

unread,
Nov 9, 2009, 6:50:14 AM11/9/09
to

The xsd:schema element takes an attribute
elementFormDefault
which can take the value 'unqualified' or 'qualified'. See
http://www.w3.org/TR/xmlschema-0/#QualLocals.

If you don't specify the attribute, as it is the case in your schemas,
it takes on the value 'unqualified' meaning any local/inline definitions
define elements in no namespace. That is why you need to put the
xmlns="" on your "serveur" element. If you don't want to do that but
rather define that elements in the targetNamespace of the schema you can use

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://domaine.tld"
xmlns="http://domaine.tld"

elementFormDefault="qualified">

<xsd:element name="definition">
<xsd:complexType>
<xsd:all>
<xsd:element name="serveur" minOccurs
="1" maxOccurs ="1" />
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>


--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

0 new messages