473,385 Members | 1,640 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,385 software developers and data experts.

XSD Complex Type

Hi,

I have a complex type which has to have its content in the xml instance
document as shown below :

<CONFIG_INFO>
<country resourceNumber="20004" fieldSecurity="5, 5">Great
Britain</label>
</CONFIG_INFO>

For this, I have defined the schema as below :

<xs:complexType name="AttributesType" mixed="true">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="resourceNumber" type="xs:string"
default="20004"/>
<xs:attribute name="fieldSecurity" type="xs:string" default="5,
5"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="CONFIG_INFO">
<xs:complexType>
<xs:all>
<xs:element name="country" type="AttributesType"/>
</xs:all>
</xs:complexType>
</xs:element>

But I also have defined a named complex type for the text contained in the
element as shown below :

<xs:complexType name="COUNTRY_TYPE">
<xs:choice>
<xs:element name="CT_UK" fixed="Great Britain" type="xs:string"/>
<xs:element name="CT_GERMANY" fixed="Germany" type="xs:string"/>
</xs:choice>
</xs:complexType>

How do I asscoiate the text portion of the element "country" so that it
contains one of the defined values in "COUNTRY_TYPE"?

Thanks and regards,
Kanchana
Nov 11 '05 #1
9 2486
You probably want to make COUNTRY_TYP Ean enumeration. Enumerations are
described at http://www.w3.org/TR/xmlschema-0/#ref10

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Kanchana D S" <ka*********@in.bosch.com> wrote in message
news:bh**********@ns2.fe.internet.bosch.com...
Hi,

I have a complex type which has to have its content in the xml instance
document as shown below :

<CONFIG_INFO>
<country resourceNumber="20004" fieldSecurity="5, 5">Great
Britain</label>
</CONFIG_INFO>

For this, I have defined the schema as below :

<xs:complexType name="AttributesType" mixed="true">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="resourceNumber" type="xs:string"
default="20004"/>
<xs:attribute name="fieldSecurity" type="xs:string" default="5, 5"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:element name="CONFIG_INFO">
<xs:complexType>
<xs:all>
<xs:element name="country" type="AttributesType"/>
</xs:all>
</xs:complexType>
</xs:element>

But I also have defined a named complex type for the text contained in the
element as shown below :

<xs:complexType name="COUNTRY_TYPE">
<xs:choice>
<xs:element name="CT_UK" fixed="Great Britain" type="xs:string"/>
<xs:element name="CT_GERMANY" fixed="Germany" type="xs:string"/>
</xs:choice>
</xs:complexType>

How do I asscoiate the text portion of the element "country" so that it
contains one of the defined values in "COUNTRY_TYPE"?

Thanks and regards,
Kanchana

Nov 11 '05 #2
Kanchana D S wrote:
I am aware of enumerations, but my doubt is not with respect to that point.
My doubt is - If I have to associate the "Text" portion of the element
"country" with the complex type "COUNTRY_TYPE", then how is it possible ?

What is "Text portion"? It's just content. Here is the schema using
enumerations just as Dare suggested:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:complexType name="AttributesType" mixed="true">
<xs:simpleContent>
<xs:extension base="COUNTRY_TYPE">
<xs:attribute name="resourceNumber" type="xs:string"
default="20004"/>
<xs:attribute name="fieldSecurity" type="xs:string" default="5,
5"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="CONFIG_INFO">
<xs:complexType>
<xs:all>
<xs:element name="country" type="AttributesType"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:simpleType name="COUNTRY_TYPE">
<xs:restriction base="xs:string">
<xs:enumeration value="Great Britain"/>
<xs:enumeration value="Germany"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
It does not make sense for me to extend "AttributesType" from COUNTRY_TYPE
as they are 2 different global types. But I want the element "country" to
have attributes from "AttributesType" and its content from the COUNTRY_TYPE
global type, as I have shown below. How is this possible ?

<country resourceNumber="20004" fieldSecurity="5, 5">Great Britain</country>

Regards,
Kanchana

Nov 11 '05 #4
Kanchana D S wrote:
It does not make sense for me to extend "AttributesType" from COUNTRY_TYPE
as they are 2 different global types. But I want the element "country" to
have attributes from "AttributesType" and its content from the COUNTRY_TYPE
global type, as I have shown below. How is this possible ?

Sounds like you are talking about multiple inheritance? XML Schema doesn't
support that.
But your AttributesType then looks quite artificial - if you want it to be
just collection of attribute definitions, why don't you use xs:attributeGroup?
Then country element definition can extend simple type COUNTRY_TYPE by
providing attribute definitions:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:attributeGroup name="myAttrs">
<xs:attribute name="resourceNumber" type="xs:string" default="20004"/>
<xs:attribute name="fieldSecurity" type="xs:string" default="5,
5"/>
</xs:attributeGroup>
<xs:element name="CONFIG_INFO">
<xs:complexType>
<xs:all>
<xs:element name="country">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="COUNTRY_TYPE">
<xs:attributeGroup ref="myAttrs"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:simpleType name="COUNTRY_TYPE">
<xs:restriction base="xs:string">
<xs:enumeration value="Great Britain"/>
<xs:enumeration value="Germany3"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #5
yeah your solution works for a specific case, but I am looking at a more
frequent usage of the 2 complex types wherein it might be too complicated to
use extensions like you have shown. See, the structure of my instance
document is as follows :

<PANEL_CLUSTER>
<CONFIG_INFO>
<label resourceNo="rr20003" fieldSecurity="5, 5">Cluster with 2
MagicPanels</label>
<country resourceNo="rr20004" fieldSecurity="5, 5">Great
Britain</country>
</CONFIG_INFO>
<APP_INFO>
<dialogFile>PanelClusterDlg.resx</dialogFile>
<deletable>0</deletable>
<default>1</default>
<subNodesPossible>1</subNodesPossible>
<helpIndex>%rr80202</helpIndex>
<icoName>PANEL_CLUSTER.ico</icoName>
<displayName>%rr80202</displayName>
<saveName>%rr80202</saveName>
<checkdate>null</checkdate>
</APP_INFO>
</PANEL_CLUSTER>

Now, I want to combine the attributes "resourceNo" and "fieldSecurity" under
one global complex type as all "CONFIG_INFO" elements in my instance
document will have to compulsorily contain these 2 attributes ( and there
will be multiple "CONFIG_INFO" elements in the instance document ). However
the content of these elements is variable and sometimes the content is one
of an enumeration (such as COUNTRY_TYPE), which is why I want to make this
enumeration as a global complex type. So the question is , I should make
each element under CONFIG_INFO contain the attributes "resourceNo" and
"fieldSecurity" and the content of some of these elements should be of an
enumerated type. How do I achieve both the goals ? And if multiple
inheritance is not supported what is the other alternative ? Or do I have to
follow the method you have suggested in the previous mail strictly ?

Regards,
Kanchana
Nov 11 '05 #6
Kanchana D S wrote:
Now, I want to combine the attributes "resourceNo" and "fieldSecurity" under
one global complex type

What's the point to define such a type instead of named attribute group?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #7
Yeah I agree with you that it can be an attribute group, but still my
problem is not solved. Even with the previous solution you suggested I still
have some problem as I had mentioned in the earlier mail.

Regards,
Kanchana
Nov 11 '05 #8
Kanchana D S wrote:
And to also add to my previous mail, the elements under "CONFIG_INFO" can
also be empty, so how then will the attributeGroup be referenced ?


Or if saying "can" you meant it may be empty or contain anything, that's just
xs:string:
<xs:element name="foo">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="myAttrs"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #9
Thanks, that helped!

Regards,
Kanchana
Nov 11 '05 #10

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

Similar topics

3
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
0
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the...
3
by: Arthur | last post by:
Spending the morning avoiding responsibilities, and seeing what it would take to color some complex numbers. class color_complex(complex): def __init__(self,*args,**kws):...
17
by: Chris Travers | last post by:
Hi all; I just made an interesting discovery. Not sure if it is a good thing or not, and using it certainly breakes first normal form.... Not even sure if it really works. However, as I am...
4
by: Mantorok Redgormor | last post by:
With what specifier do I use to print a variable of a complex type? The man page for printf doesn't even say. - nethlek
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
12
by: vj | last post by:
Hi! I have a piece of code (shown below) involving complex numbers. The code is not running and giving error ("Invalid floating point operation" and "SQRT:Domain error"). I would be very...
3
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types -...
6
by: jacob navia | last post by:
Consider this code: < code > #include <complex.h> int main(void) { double complex c = 0.4+2.9I; c = ~c; } < end code >
4
by: BiDi | last post by:
I have been trying to subclass complex, but I am not able to get the right-hand arithmetic operators working. As shown below, if an object of my subclass 'xcomplex' is added on the right of a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.