• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml schema question

 
Adam Al
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am running into this problem with xml schema, here is my issue
I have 3 schema(s), each with different name space. One schema "A" has 2 elements, one is header and the other is "Data".
Data can be any of 2 schema(s) (one or the other) , since these schema(s) do not have the same name space , I used import, but still having problem
Here are sample of I am trying to do , any help will be appreciate it. (I need this to be able use jaxb)
<?xml version="1.0" ?>
<xs:schema targetNamespace="http://testA.com/A.xsd"
xmlns:cmr="http://testA.com/A.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:itmB=http://testB.com/B.xsd
xmlns:itmC="http://testC.com/C.xsd"

attributeFormDefault="qualified" elementFormDefault="qualified">

<xs:import namespace="http://testB.com/B.xsd"
schemaLocation="B.xsd"/>
<xs:import namespace="http://testC.com/C.xsd"
schemaLocation="C.xsd"/>

<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="Header" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="message-class" form="unqualified" type="xs:string" />
<xs:attribute name="message-id" form="unqualified" type="xs:long" />
<xs:attribute name="message-date" form="unqualified" type="xs:dateTime" />
</xs:complexType>
</xs:element>
<xs:element name="Data" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:choice>
<xs:element name="B" type="itmB:B"/>
<xs:element name="C" type="itmC:C"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


Also here is sample of the schema B

<xs:schema id="B"
targetNamespace="http://testB.com/B.xsd"
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns="http://testB.com/B.xsd"
xmlns:mstns="http://testB.com/B.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="B" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Title">
<xs:complexType>
<xs:sequence>
.
.
 
Rizwan Patel
Ranch Hand
Posts: 59
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error you are getting when using JAXB?
 
g tsuji
Ranch Hand
Posts: 669
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any case, this:
<xs:element name="B" type="itmB:B"/>

should be read:

Same for itmC:C if the schema C follows the same pattern as schema B. The reason basically is that you have defined global element B rather than global type B in the schema B.
 
david fields
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this schema tutorial will help.

http://www.liquid-technologies.com/Tutorials/XmlSchemas/XsdTutorial_01.aspx
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic