OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Schema definition of element with optional children

[ Lists Home | Date Index | Thread Index ]

Stan

Thanks, this might do very nicely, I'll have to talk with the database guy 
and see if he can determine whether it's an update or insert from the key 
value.

Thanks to George and Michael as well (this is turning into an Oscar 
acceptance speech).
I'm so glad I asked now, I've learnt three techniques for my problem as well 
as how to use Schematron, something I've been meaning to look at for ages.

--

Joe




>From: "Stan Kitsis" <skits@microsoft.com>
>To: "Michael Kay" 
><mike@saxonica.com>,<joe@rightway.co.uk>,<xml-dev@lists.xml.org>
>Subject: RE: [xml-dev] Schema definition of element with optional children
>Date: Tue, 2 May 2006 11:47:37 -0700
>
>Actually, in this case, there is an Xsd solution.  It assumes that one
>of the elements in the address sequence (when the address is not
>deleted) is required and is of a simple type.  In the example below, I
>picked addressLine1 as such an element.
>
><?xml version="1.0" encoding="utf-8"?>
><xs:schema attributeFormDefault="unqualified"
>            elementFormDefault="qualified"
>            xmlns:tns="foo.com"
>            targetNamespace="foo.com"
>            xmlns:xs="http://www.w3.org/2001/XMLSchema";>
>   <xs:element name="address">
>     <xs:complexType>
>       <xs:sequence minOccurs="0">
>         <xs:element name="addressLine1" type="xs:string" />
>         <xs:element name="addressLine2" type="xs:string"/>
>         <xs:element name="city" type="xs:string"/>
>         <xs:element name="postCode" type="xs:string"/>
>         <xs:element name="country" type="xs:string"/>
>       </xs:sequence>
>       <xs:attribute name="recordStatus" type="xs:string" />
>     </xs:complexType>
>     <xs:unique name="attrOrseq">
>       <xs:selector xpath="."/>
>       <xs:field xpath="tns:addressLine1|@recordStatus"/>
>     </xs:unique>
>   </xs:element>
></xs:schema>
>
>The schema allows you to have either recordStatus attribute or
>addressLine1 element, but not both.
>
>Stan Kitsis
>Microsoft Corporation
>
>-----Original Message-----
>From: Michael Kay [mailto:mike@saxonica.com]
>Sent: Tuesday, May 02, 2006 6:55 AM
>To: joe@rightway.co.uk; xml-dev@lists.xml.org
>Subject: RE: [xml-dev] Schema definition of element with optional
>children
>
>You can't declare the type of the element to be conditional on one of
>its
>attributes, unless the attribute has the magic name xsi:type. Your only
>options are (a) to define a type that's sufficiently permissive to allow
>all
>the options, and then do extra validation using some other technology,
>or
>(b) to use different element names for the two cases. Alternatively, in
>this
>case you could use the magic xsi:nil attribute to mean status="deleted".
>
>
>Michael Kay
>http://www.saxonica.com/
>
> > -----Original Message-----
> > From: Joe Fawcett [mailto:joefawcett@hotmail.com]
> > Sent: 02 May 2006 14:48
> > To: xml-dev@lists.xml.org
> > Subject: [xml-dev] Schema definition of element with optional children
> >
> > Dear All
> >
> > I'm struggling to find the best way to restrict an element
> > that holds address data.
> > If the address is to be deleted it will look like this:
> > <address recordStatus="deleted"/>
> >
> > if it's new or an update it will be along the lines of:
> >
> > <address recordStatus="inserted">
> >   <addressLine1></addressLine1>
> >   <addressLine2></addressLine2>
> >   <city></city>
> >   <postCode></postCode>
> >   <country></country>
> > </address>
> >
> > with various fields being optional, these are UK addresses only.
> >
> > What's the most efficient way to declare this using XSD only
> > as I believe I can't say, "if recordStatus = 'deleted' then..." etc?
> >
> > I believe I have to give a choice of two types but this seems tedious?
> >
> > Thanks
> >
> > Joe
> >
> >
> >
> > -----------------------------------------------------------------
> > The xml-dev list is sponsored by XML.org
> > <http://www.xml.org>, an initiative of OASIS
> > <http://www.oasis-open.org>
> >
> > The list archives are at http://lists.xml.org/archives/xml-dev/
> >
> > To subscribe or unsubscribe from this list use the subscription
> > manager: <http://www.oasis-open.org/mlmanage/index.php>
> >
>
>
>-----------------------------------------------------------------
>The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
>initiative of OASIS <http://www.oasis-open.org>
>
>The list archives are at http://lists.xml.org/archives/xml-dev/
>
>To subscribe or unsubscribe from this list use the subscription
>manager: <http://www.oasis-open.org/mlmanage/index.php>
>
>
>-----------------------------------------------------------------
>The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
>initiative of OASIS <http://www.oasis-open.org>
>
>The list archives are at http://lists.xml.org/archives/xml-dev/
>
>To subscribe or unsubscribe from this list use the subscription
>manager: <http://www.oasis-open.org/mlmanage/index.php>
>






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS