Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2006

Tip: Looking for answers? Try searching our database.

XSD Restrictions help please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AdamH - 25 Apr 2006 15:52 GMT
Greetings all.
Is it possible to create a schema to enforce the following issue.

If the value for required Attribute A within Element E has an enumerated
value of ‘myType’ then element E also needs to have Attribute B.

Xml example below
E=Item
A=type
B=len

<Items>
    <Item type=” myType” len=”5” />
    <Item type=” NOTmyType” />
</Items>

Any help or a point in a semi right direction would be very helpful :)
Martin Honnen - 25 Apr 2006 18:46 GMT
> Is it possible to create a schema to enforce the following issue.
>
[quoted text clipped - 10 lines]
>     <Item type=” NOTmyType” />
> </Items>

No, you can't put constraints on one attribute based on the value of
another attribute, not with the W3C XSD schema language.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

AdamH - 25 Apr 2006 18:58 GMT
was afraid of that.
thanks for the validation :)
is it then common practice to have different node names to start with, and
not differentiate by node type?

> > Is it possible to create a schema to enforce the following issue.
> >
[quoted text clipped - 13 lines]
> No, you can't put constraints on one attribute based on the value of
> another attribute, not with the W3C XSD schema language.
George Bina - 26 Apr 2006 08:50 GMT
Hi Adam,

XML Schema allows you to specify the type of an element in the instance
using the schema instance type attribute, xsi:type. Here it is a sample
schema and a valid instance that shows that.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="Items">
   <xs:complexType>
     <xs:sequence maxOccurs="unbounded">
       <xs:element ref="Item"/>
     </xs:sequence>
   </xs:complexType>
 </xs:element>
 <xs:element name="Item" type="AbstractItemType"/>
 <xs:complexType name="AbstractItemType" abstract="true"/>
 <xs:complexType name="myType">
   <xs:complexContent>
     <xs:extension base="AbstractItemType">
       <xs:attribute name="len" type="xs:integer"/>
     </xs:extension>
   </xs:complexContent>
 </xs:complexType>

 <xs:complexType name="NOTmyType">
   <xs:complexContent>
     <xs:extension base="AbstractItemType">
     </xs:extension>
   </xs:complexContent>
 </xs:complexType>
</xs:schema>

<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Item xsi:type="myType" len="5"/>
 <Item xsi:type="NOTmyType"/>
</Items>

Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
AdamH - 26 Apr 2006 16:07 GMT
hmmmm  good food for thought. Thank you.
gotta take a closer look at this and see if i can make it fit our needs.

btw i love it when the answer takes you on a ride of exploration and for
that i really thank you :)

> Hi Adam,
>
[quoted text clipped - 39 lines]
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.