473,396 Members | 1,734 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.

either/or elements in xml schema

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>

The xml schema for this is simple (so simple that I won't
mention it). The problem is that on some computers, the network
information should be determined by dhcp, and all of the usual
information is not needed. In these cases the xml should look like
this

<networkinfo>
<dhcp />
</networkinfo>

I don't know how to write an xml schema that requires either n
elements (ie- ipaddress, hostname, and dnsserver), or a single
different element (ie- dhcp). I could bin the n elements in another,
and then use xsd:choice, although it seems a waste to add another tag
for this reason only.

I thank anyone in advance for suggestions.

thank
-I

ps- extra credit if you can extend this to describe an arbitrary
number of ethernet cards (eth0 ipaddress, eth1 ipaddress, etc.)
Jul 20 '05 #1
2 2381

"inquirydog" <in********@hotmail.com> schrieb im Newsbeitrag
news:80**************************@posting.google.c om...
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>

The xml schema for this is simple (so simple that I won't
mention it). The problem is that on some computers, the network
information should be determined by dhcp, and all of the usual
information is not needed. In these cases the xml should look like
this

<networkinfo>
<dhcp />
</networkinfo>

I don't know how to write an xml schema that requires either n
elements (ie- ipaddress, hostname, and dnsserver), or a single
different element (ie- dhcp). I could bin the n elements in another,
and then use xsd:choice, although it seems a waste to add another tag
for this reason only.

I thank anyone in advance for suggestions.

thank
-I

ps- extra credit if you can extend this to describe an arbitrary
number of ethernet cards (eth0 ipaddress, eth1 ipaddress, etc.)


Hi

as I understand the problem this should be a solution

The Schema:

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="networkinfo" type="info"/>

<xs:complexType name="info" abstract="true"/>

<xs:complexType name="standardinfo">
<xs:complexContent>
<xs:extension base="info">
<xs:sequence>
<xs:element name="ipadress" type="xs:string"/>
<xs:element name="hostname" type="xs:string"/>
<xs:element name="dnsserver" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="dhcpinfo">
<xs:complexContent>
<xs:extension base="info">
<xs:sequence>
<xs:element name="dhcp" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

and a sampleinstance

<networkinfo xsi:type="standardinfo">
<ipadress/>
<hostname/>
<dnsserver/>
</networkinfo>

note that the schema uses three types: an abract info type and two types
(standardinfo and dhcpinfo) that extend the abstract type. the only element
is of typ info. For the instance document this means that you have replace
the type of the element by one of the none abstact subtypes. (with the
xsi:type attribute). An Instance of dhcpinfo would look like:

<networkinfo xsi:type="dhcpinfo">
<dhcp/>
</networkinfo>

greetings

hd
Jul 20 '05 #2
Hi,

You could also do something simpler using xsd:choice, like:

<xs:element name="networkinfo" type="info"/>
<xs:complexType name="info">
<xs:choice>
<xs:sequence>
<xs:element name="ipadress" type="xs:string"/>
<xs:element name="hostname" type="xs:string"/>
<xs:element name="dnsserver" type="xs:string"/>
</xs:sequence>
<xs:element name="dhcp" type="xs:string"/>
</xs:choice>
</xs:complexType>

Hope that helps,
Priscilla
-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

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

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
1
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
0
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.