473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Schema help needed

Hello,

I need to create an xsd to validate the following type of xml:
<?xml version="1.0" encoding="UTF-8"?>
<root
<exception1 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>

<exception2 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception2>

<exception3 xsi:type="ExceptionBType">
<Type>2</Type>
<Info>Bla bla</Info>
</exception3>

</root>

My constraints are:
- I have a hierarchy of ExceptionType
- For all ExceptionAType, <Typemust be "1"
- For all ExceptionBType, <Typemust be "2"

With the following schema, I can validate the xml:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="1" ></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="2"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"></xs:element>
<xs:element name="exception2" type="ExceptionType"></xs:element>
<xs:element name="exception3" type="ExceptionType"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>

But I am not happy with that, because, I need to repeat the element
<Infoin each exception definitions.
Is there an other way of doing that, by using extension or other tricks
?

Thanks

Olivier

Sep 12 '06 #1
4 1289
Hi Olivier,

The content model that results after an extension is a sequence of the
base particles followed by the new added particles so you can work with
extension only if you have the Type as the last element. Have a look at
the IPO example in the schema spec for a sample, look at the Address
and USAddress/UKAddress types.
In your case if the content following the Type element is mode complex
and you do not want to repeat that then you can put that in a group and
make a reference to that group after the Type element.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

ol**************@algosyn.com wrote:
Hello,

I need to create an xsd to validate the following type of xml:
<?xml version="1.0" encoding="UTF-8"?>
<root
<exception1 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>

<exception2 xsi:type="ExceptionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception2>

<exception3 xsi:type="ExceptionBType">
<Type>2</Type>
<Info>Bla bla</Info>
</exception3>

</root>

My constraints are:
- I have a hierarchy of ExceptionType
- For all ExceptionAType, <Typemust be "1"
- For all ExceptionBType, <Typemust be "2"

With the following schema, I can validate the xml:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="1" ></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:restriction base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="2"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"></xs:element>
<xs:element name="exception2" type="ExceptionType"></xs:element>
<xs:element name="exception3" type="ExceptionType"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>

But I am not happy with that, because, I need to repeat the element
<Infoin each exception definitions.
Is there an other way of doing that, by using extension or other tricks
?

Thanks

Olivier
Sep 12 '06 #2
Thanks for your help George,

If I use extension, which I prefer because it implements a kind of OO
inheritance, how can I constraint <Type>1</Typein ExceptionAType and
<Type>2</Typein ExceptionBType ?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"/></xs:element>
<xs:element name="exception2" type="ExceptionType"/></xs:element>
<xs:element name="exception3" type="ExceptionType"/></xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>
Thanks

Olivier

Sep 12 '06 #3
Hi Olivier,

As I said in my initial reply, you can use extension but in that case
you need to have first Info and then Type, like below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="1"/>

</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="2"/>

</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"/>
<xs:element name="exception2" type="ExceptionType"/>
<xs:element name="exception3" type="ExceptionType"/>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>

and the instance document:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<exception1 xsi:type="ExceptionAType">
<Info>Bla bla</Info>
<Type>1</Type>
</exception1>

<exception2 xsi:type="ExceptionAType">
<Info>Bla bla</Info>
<Type>1</Type>
</exception2>

<exception3 xsi:type="ExceptionBType">
<Info>Bla bla</Info>
<Type>2</Type>
</exception3>

</root>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

ol**************@algosyn.com wrote:
Thanks for your help George,

If I use extension, which I prefer because it implements a kind of OO
inheritance, how can I constraint <Type>1</Typein ExceptionAType and
<Type>2</Typein ExceptionBType ?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string"></xs:element>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"/></xs:element>
<xs:element name="exception2" type="ExceptionType"/></xs:element>
<xs:element name="exception3" type="ExceptionType"/></xs:element>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>
Thanks

Olivier
Sep 12 '06 #4
Thank again George,

What I forget to say is that the xsd will be used to generate java code
for a web service (wsdl2java)
As we need to be able to access the <Typevalue polymorphically (?), I
need to put <Typein the base class ExceptionType.
ExceptionType ex = getException(); // can be any exception subclasses
System.out.println(ex.getType());

And then, I have no idea of how to constraint the <Typevalue
depending the subclass ...

Kind regards,

Olivier

George Bina wrote:
Hi Olivier,

As I said in my initial reply, you can use extension but in that case
you need to have first Info and then Type, like below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexType abstract="true" name="ExceptionType">
<xs:sequence>
<xs:element name="Info" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ExceptionAType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="1"/>

</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="ExceptionBType">
<xs:complexContent>
<xs:extension base="ExceptionType">
<xs:sequence>
<xs:element name="Type" type="xs:string" fixed="2"/>

</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="RootType">
<xs:sequence>
<xs:element name="exception1" type="ExceptionType"/>
<xs:element name="exception2" type="ExceptionType"/>
<xs:element name="exception3" type="ExceptionType"/>
</xs:sequence>
</xs:complexType>

<xs:element name="root" type="RootType"></xs:element>
</xs:schema>
Sep 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed Trembicki-Guy | last post by:
Does anyone know of an existing tool or template to merge the contents of a base schema and an extension schema that uses the <redefine> tag to extend the base schema? I need to extract a subset...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
2
by: inquirydog | last post by:
I am trying to store my computer network information in an xml file, and plan to write an xml schema for the file. The general format of the xml should be like this <networkinfo>...
1
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm designing my first XML-based application and am stuck on an issue that I presume is pretty simple. I'm trying to write a schema that can be used to validate my XML file. ...
2
by: kamp | last post by:
Hello, Below is a snippet from a schema. The second enumeration should contain an i umlaut (archaïsch) but when I use this schema with Altova's Stylevision software the iumlaut is not displayed...
1
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a...
6
by: LesleyW | last post by:
Hi Apologies if this is a really dumb question, but being new to XML and Schemas, I wonder if giving the namespace for eg xsd or xsi as a website address means that the user has to be online...
7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
0
by: BC3Tech | last post by:
I'm creating a system that uses XML to store an audit trail of the steps that it has been through in the system. The way the schema is defined, there is a "Tag" for every application that...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.