Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

targetNamespace question in XSD

Status
Not open for further replies.

jonstalnaker

Programmer
Feb 25, 2008
2
US
This version of my XSD validates fine:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=" elementFormDefault="qualified">

<xs:element name="point">
<xs:complexType>
<xs:attribute name="le" type="xs:decimal" use="required" />
</xs:complexType>
</xs:element>

<xs:element name="detail">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>

<xs:element name="event">
<xs:complexType>
<xs:all>
<xs:element ref="point" />
<xs:element ref="detail" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>

</xs:schema>

However when I add a targetNamespace to the schema tag, it breaks the reference in the Event element to both Point and Detail. Can anyone explain to me why this breaks and what I need to do to add a targetNamespace?

Thanks!
 
Warning: I am not an XML Schema expert.

That said, the elements which are named by the ref attribute are defined in the target namespace, so you will need to append that namespace in the ref as well. You can find some useful examples in the Technical Recommendation from W3C.

Tom Morrison
 
The transition from no target namespace to certain target namespace in this stripped down case can be done like this.

[1] The original xml

[1.1] Change _only_ the root element (say "root" by coincidence) adding a default namespace, urn:tt-1453488:tns, absolutely arbitary here, so as to save you the work of adding or not-adding prefixes.
[tt]
<root [blue]xmlns="urn:tt-1453488:tns"[/blue]>
<!-- etc etc nothing to change -->
</root>
[/tt]
[1.2] If your validation tool uses the XMLSchema-instance's schemaLocation attribute to locate the schema, append it accordingly to the root in place of what you have at present at noNamespaceSchemaLocation attribute.

[2] The schema

[2.1] Add the targetNamespace you've in mind. Something like this.
[tt]
<xs:schema xmlns:xs="[ignore][/ignore]"
[blue]elementFormDefault="qualified"
targetNamespace="urn:tt-1453488:tns"[/blue]>
[/tt]
Then it should be ready for this particular design?
 
Thanks for your responses! I'm stuck in meetings today but as soon as I can get back to the problem I'll try to apply your suggestions. I will let you know how things go.

Thanks,
Jon Stalnaker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top