Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this XSD import namespace for?

I have an xsd document that starts with:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace"     schemaLocation="http://www.w3.org/2001/xml.xsd"/>
    <xs:complexType name="T_segment">
        <xs:sequence>
            <xs:element ref="element" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute ref="xml:space" use="required"/>
        <xs:attribute ref="id" use="required"/>
    </xs:complexType>
...

When I try to use this xsd in a mapping application like BizTalk it blows up complaining about namespaces. So, I remove the xs:import namespace tag and it complains about the xs:attribute ref="xml:space" tag. So, I remove that and it seems to work ok (at least doesn't blow up).

My question is, what are those tags for? By removing them am I breaking the xsd?

From what I know namespaces are to avoid conflicts. But in the xsd everything is prefixed by xs and the schema itself has xmlns:xs="http://www.w3.org/2001/XMLSchema". I'm not sure what that import is for.

like image 969
dtc Avatar asked Jan 22 '10 21:01

dtc


1 Answers

The <xs:import /> element imports the XML namespace into the schema. The imported namespace contains the definition for the "space" attribute. The <xs:attribute ref="xml:space" use="required"/> bit defines a required "space" attribute for the "T_segment" complex type by reference from the imported schema (i.e. so that you don't have to rewrite the definition). The space attribute essentially gives you the ability to define whether whitespace is significant for the element or not.

Now, depending on application you actually might be breaking things because essentially you are removing a constraint from the complex type that might be relevant to the application consuming the document described by this schema. Without knowing more of the application it is difficult to say if this is significant in your case or not.

like image 82
Petri Pellinen Avatar answered Nov 12 '22 13:11

Petri Pellinen