• 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 Schema, choice and other stuff

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to validate a login response message. A successfull response looks like this :
<FoXML version="2.0" descriptor="bb.activetrader.response">
<TraderResponse type="loginack" login="hileyw">
<User internal_user_id="644" global_staff_id="47088981" ldap="hileyw" name="Hiley, Wayne" sales_team_id="" sales_team="" user_type_id="1" read_only="0" valid="1" active="0" modified_date="Mar 23 2004 3:05PM" modified_by="TraderLoginServer" sales_list_member="0" oneview_sales_team_id="" oneview_sales_team="" see_all_orders="0" />
</TraderResponse>
</FoXML>
and an unsuccessful response looks like this :
<FoXML version="2.0" descriptor="bb.activetrader.response">
<TraderResponse type="loginnack" reason="Not a valid trader" login="vdfvdfvdv" />
</FoXML>

This is my first attempt at an xml schema and I'm getting a bit stuck. This my top level bit.It basically says I get a standard header, then either one of the two messages.
<xsd:element name="FoXML">
<xsd:complexType>
<xsd:attribute name="version" type="xsd:string" />
<xsd:attribute name="descriptor" type="xsd:string" />
</xsd:complexType>
<xsd:choice>
<xsd:element name="TraderResponse" type="xsd:loginAccepted" />
<xsd:element name="TraderResponse" type="xsd:loginNotAccepted" />
</xsd:choice>
</xsd:element>
Will the choice bit work ? I think it will fail because the elements are called the same thing but can be formed differently.
This XML is not set in stone so I can change to make it easier to parse if that would make more sense. I've not done much xml so I'm a bit confused !
thanks,
D.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bumpity-bump
Anyone got any advice ?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's an interesting question -- I hadn't encountered such a situation before.
I see three options here:
1) browse a book
2) browse the spec
3) test it
Right now, I'm headed towards the bed so I'm not going to do even the last one myself.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don,
You may try this:
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xsd:complexType name="ValidityCheck">
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="login" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="loginNotAccepted">
<xsd:complexContent>
<xsd:extension base="ValidityCheck">
<xsd:attribute name="reason" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="loginAccepted">
<xsd:complexContent>
<xsd:extension base="ValidityCheck">
<xsd:sequence>
<xsd:element name="User">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="internal_user_id" type="xsd:integer"/>
<xsd:attribute name="global_staff_id" type="xsd:integer"/>
<xsd:attribute name="ldap" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="TraderResponse" type="ValidityCheck" abstract="true"/>
<xsd:element name="loginNotAccepted" Type="loginNotAccepted" substitutionGroup="TraderResponse"/>
<xsd:element name="loginAccepted" type="loginAccepted" substitutionGroup="TraderResponse"/>
<xsd:element name="FoXML">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="TraderResponse" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Which will work for your scenario...
The XML file will look like:
Valid Login XML:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<FoXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sameElementName.xsd">

<TraderResponse type="loginack" login="vdfvdfvdv" xsi:type="loginAccepted">
<User
internal_user_id="644"
global_staff_id="47088981"
ldap="hileyw"
name="Hiley, Wayne"
/>
</TraderResponse>
</FoXML>

Invalid Login XML:
------------------
<?xml version="1.0" encoding="UTF-8"?>
<FoXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="sameElementName.xsd">

<TraderResponse type="loginack" login="vdfvdfvdv" reason="Not a valid trader" xsi:type="loginNotAccepted"/>
</FoXML>

You can modify it to ur requirement.. but make sure all the complext type declaration and the element declaration are to be global.
I guess I answered your question!
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Vaidya
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew, thanks a lot for spending the time to help me. I've checked it and it works, but I'm not sure how yet, so I'll have to go through and have a look....maybe coming back with questions !
cheers,
D.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, Lasse, cheers for the link too, that's now in my "favourites"
D.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Don Kiddick:
oh, Lasse, cheers for the link too, that's now in my "favourites"
D.

Want another one?
 
reply
    Bookmark Topic Watch Topic
  • New Topic