473,796 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Excep tionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>

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

<exception3 xsi:type="Excep tionBType">
<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:complexTy pe abstract="true" name="Exception Type">
<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:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<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:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<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:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"></xs:element>
<xs:element name="exception 2" type="Exception Type"></xs:element>
<xs:element name="exception 3" type="Exception Type"></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 1306
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="Excep tionAType">
<Type>1</Type>
<Info>Bla bla</Info>
</exception1>

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

<exception3 xsi:type="Excep tionBType">
<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:complexTy pe abstract="true" name="Exception Type">
<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:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<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:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:restricti on base="Exception Type">
<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:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"></xs:element>
<xs:element name="exception 2" type="Exception Type"></xs:element>
<xs:element name="exception 3" type="Exception Type"></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:complexTy pe abstract="true" name="Exception Type">
<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:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"/></xs:element>
<xs:element name="exception 2" type="Exception Type"/></xs:element>
<xs:element name="exception 3" type="Exception Type"/></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:complexTy pe abstract="true" name="Exception Type">
<xs:sequence>
<xs:element name="Info" type="xs:string "></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="1"/>

</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="2"/>

</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"/>
<xs:element name="exception 2" type="Exception Type"/>
<xs:element name="exception 3" type="Exception Type"/>
</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="Excep tionAType">
<Info>Bla bla</Info>
<Type>1</Type>
</exception1>

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

<exception3 xsi:type="Excep tionBType">
<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:complexTy pe abstract="true" name="Exception Type">
<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:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"/></xs:element>
<xs:element name="exception 2" type="Exception Type"/></xs:element>
<xs:element name="exception 3" type="Exception Type"/></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.prin tln(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:complexTy pe abstract="true" name="Exception Type">
<xs:sequence>
<xs:element name="Info" type="xs:string "></xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexTy pe name="Exception AType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="1"/>

</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="Exception BType">
<xs:complexCont ent>
<xs:extension base="Exception Type">
<xs:sequence>
<xs:element name="Type" type="xs:string " fixed="2"/>

</xs:sequence>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="RootType" >
<xs:sequence>
<xs:element name="exception 1" type="Exception Type"/>
<xs:element name="exception 2" type="Exception Type"/>
<xs:element name="exception 3" type="Exception Type"/>
</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
1696
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 of a very large schema so that I can use it with JAXB. I have created an xslt template to do this, and it works as long as the entire schema is in one file. The trouble is, I need to work with an extended schema, and xslt does not recognize the...
4
2397
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 generate any of the specific instances. sample schema one: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="base">
2
2408
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> <ipaddress>1.2.3.4</ipaddress> <hostname>qwerty</hostname> <dnsserver>7.7.7.7</dnsserver> </networkinfo>
1
1653
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. However, I want to define components of this schema in different files so that I can do isolated tests on these subsections. As an example, consider this XML file: <container> <name>Me</name>
2
1863
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 properly. So I changed it into a character entity. I tried several entity declarations (examples found on the web) but none of them worked i.e. Stylevision refused to load the schema. So, I want to know the following: is it possible to use...
1
2689
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 "write to the database", we store the dataset's diffgram in the audit table. To render the audit report we load the diffgram into a generic DataSet and bind it to a grid. All works well unless the document's schema had an <xs:import> to bring...
6
4434
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 when they run the app? If so, what should I do if I can't guarantee that they will be? Can I bring all these files into the app? Is that desirable? I'm about to write an app that takes an XML file as input, using Visual Studio 2005 Express and SQL...
7
6235
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 in the same format as the XSD (the XML file/string was created using this same schema). The XML file/string may contain data for a single table or for several tables at once. The question is:
0
1837
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 performs modifications to any data, and "Fields" inside the tag that outline the changes that were made. Applications in the flow of the system read in these XML files and will "overlay" these tags in order to obtain data for all fields that were...
9
3021
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> <binaryobject3></binaryobject3>
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.