Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > either/or elements in xml schema

Reply
Thread Tools

either/or elements in xml schema

 
 
inquirydog
Guest
Posts: n/a
 
      08-09-2004
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.)
 
Reply With Quote
 
 
 
 
Helmut Dirtinger
Guest
Posts: n/a
 
      08-09-2004

"inquirydog" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) 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"
xmlnss="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


 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      08-09-2004
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML Schema to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments