Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import XSD types into root schema?

Tags:

java

xml

xsd

sax

This is my existing XSD schema in foo.xsd, that declares just the type:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
  targetNamespace="foo">
  <xs:complexType name="alpha">
    <!-- skipped -->
  </xs:complexType>
</xs:schema>

This is another schema, that declares the element:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
  targetNamespace="foo">
  <xs:import schemaLocation="foo.xsd" namespace="foo" />
  <xs:element name="RootElement" type="alpha"/>
</xs:schema>

This is what I'm getting from SAX parser in Java:

"The namespace attribute 'foo' of an <import> element information 
item must not be the same as the targetNamespace of the schema it exists in."

What am I doing wrong?

like image 280
yegor256 Avatar asked Jan 18 '12 03:01

yegor256


People also ask

How do you define a root element in XSD?

The root element defines the first element of the XML document and defines a reference to the root complexType. The root complexType is the complexType from which all other complexTypes are related to in their ancestry, whether the root is the parent, grand parent, great grand parent, etc.

Which is the root element of every XSD?

XSD - The <schema> Element The <schema> element is the root element of every XML Schema.

What is XSD import?

<xsd:import> ElementIdentifies a namespace whose schema components are referenced by the containing schema.


1 Answers

When the targetNamespace (tns) attributes of the involved XSDs are specified and the same, only xsd:include is allowed (a targetNamespace attribute cannot have empty string as its value).

However, one may include a schema (s1) without a tns from a schema (s2) that has a tns; the net effect is s1 components assume the namespace of the s2 schema. This usage is often referred to as chameleonic composition.

A reference on SO describing the difference between the two, is here.

like image 54
Petru Gardea Avatar answered Sep 30 '22 03:09

Petru Gardea