• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Validation using XML Schema

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Is there a way to restrict the value of one xml element on the basis of another xml element's value ?

(e.g)
Valid values for Item = Type1, Type2, Type3
Valid values for SKU = Value1, Value2, Value3

If the value of Item is Type1, then the value of SKU should be Value1.

Valid XML
<XMLRoot>
<Item>Type1</Item>
<SKU>Value1</SKU>
</XMLRoot>

Invalid XML
<XMLRoot>
<Item>Type1</Item>
<SKU>Value2</SKU>
</XMLRoot>

Any help is appreciated.

Thanks
Philip
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read this post a couple of days back and have been thinking about it and this is what I feel -

What you ask seems to be like creating a data construct with two primary keys. But, if you must, then I would guess that you will need to define a few complex types and define a sequence of two elements for that type.

I feel a better way of modelling this data would be to make one of the elements an attribute or even both of them as attributes say name, SKU.



- m
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And BTW, I deleted your duplicate posting of the same content as there were no responses to that post.

- m
 
Philip Manual
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Madhav,

Thanks for your reply.
Based on the requirements, I cannot make them as attributes. The XML i gave in my original post was just an example. The actual XML is for registration purpose. A snippet of the XML would be

<UserType>A</UserType>
<Access>1</Access>

Designing them as Individual elements/tags instead of attributes, makes sure all valiation is done by the XML parser instead of validating these elements in code.

So, the workaround/solution I used for this issue is to create complexTypes for various valid combination (Just the way you mentioned). Luckily, I had just two combination.

Regards,
Philip
 
reply
    Bookmark Topic Watch Topic
  • New Topic