p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XML
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 23rd, 2009, 10:35 AM
Registered User
Points: 70, Level: 1
Points: 70, Level: 1 Points: 70, Level: 1 Points: 70, Level: 1
Activity: 38%
Activity: 38% Activity: 38% Activity: 38%
 
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Default Linking the attribute value in XML

Hi All,

I have a Xml document and a Xml Schema document. In xml Schema i have define sum type which i am using to validate XMl Document.

I want to link the attribute value with one another.

As per the below code i want Regionid and regionType should be linked with each other.

For example : In XMl document it should only allow RegionID="ER" and reion="Europe and Russia"

it should not allow other values with reionID="ER" and vice versa.


below is the Code of XMl Schema :


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="User" minOccurs="0" maxOccurs="6">
<xs:complexType>
<xs:attribute name="region" use="required" type="regiontype"/>
<xs:attribute name="regionId" use="required" type="regionIdtype"/>
</xs:complexType>
</xs:element>
</xs:schema>


<xs:simpleType name="regiontype">
<xs:restriction base="xs:NMTOKENS">
<xs:enumeration value="Europe and Russia"/>
<xs:enumeration value="North America"/>
<xs:enumeration value="Latin and South America"/>
<xs:enumeration value="Africa"/>
<xs:enumeration value="Middle East"/>
<xs:enumeration value="Far East and Australsia"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="regionIdtype">
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="ER"/>
<xs:enumeration value="NA"/>
<xs:enumeration value="LSA"/>
<xs:enumeration value="AF"/>
<xs:enumeration value="ME"/>
<xs:enumeration value="FEA"/>
</xs:restriction>
</xs:simpleType>


XMl Structure :
===============
<?xml version="1.0" encoding="UTF-8"?>
<User regionId="ER" region="Europe and Russia">

</User>

How can i achieve this.

Thanks

-Hari
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 23rd, 2009, 10:42 AM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
Default

You would need to "normalize" your data i.e. you need to put only the regionId attribute on the User element and then you need to define a Regions element with Region child elements where RegionId and RegionName are listed.
Then you can define a key/keyreference.
__________________
Martin Honnen
Microsoft MVP - XML
My blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 23rd, 2009, 11:01 AM
Authorized User
Points: 156, Level: 3
Points: 156, Level: 3 Points: 156, Level: 3 Points: 156, Level: 3
Activity: 38%
Activity: 38% Activity: 38% Activity: 38%
 
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Martin,

Thanks for your reply.

Could you please give me some example how to do that.

Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 23rd, 2009, 11:52 AM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
Default

Thinking about it again my suggestion is not without problems as it requires you to duplicate the information specified in the simply types as data in the instance document but as long as no one comes up with something better here is what I had in mind:
Code:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="User" minOccurs="0" maxOccurs="6">
          <xs:complexType>
            <xs:attribute name="regionId" use="required" type="regionIdtype"/>
          </xs:complexType>
        </xs:element>
        <xs:element name="Regions">
          <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
              <xs:element name="Region">
                <xs:complexType>
                  <xs:attribute name="Id" type="regionIdtype"/>
                  <xs:attribute name="Name" type="regiontype"/>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:key name="regid">
      <xs:selector xpath="Regions/Region"/>
      <xs:field xpath="@Id"/>
    </xs:key>
    <xs:keyref name="regidref" refer="regid">
      <xs:selector xpath="User"/>
      <xs:field xpath="@regionId"/>
    </xs:keyref>
  </xs:element>

  <xs:simpleType name="regiontype">
    <xs:restriction base="xs:NMTOKENS">
      <xs:enumeration value="Europe and Russia"/>
      <xs:enumeration value="North America"/>
      <xs:enumeration value="Latin and South America"/>
      <xs:enumeration value="Africa"/>
      <xs:enumeration value="Middle East"/>
      <xs:enumeration value="Far East and Australsia"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="regionIdtype">
    <xs:restriction base="xs:NMTOKEN">
      <xs:enumeration value="ER"/>
      <xs:enumeration value="NA"/>
      <xs:enumeration value="LSA"/>
      <xs:enumeration value="AF"/>
      <xs:enumeration value="ME"/>
      <xs:enumeration value="FEA"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
Code:
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="test2009102301Xsd.xml">
  
  <User regionId="ER"/>
  
  <Regions>
    <Region Id="ER" Name="Europe and Russia"/>
    <Region Id="NA" Name="North America"/>
    <Region Id="LSA" Name="Latin and South America"/>
    <Region Id="AF" Name="Africa"/>
    <Region Id="ME" Name="Middle East"/>
    <Region Id="FEA" Name="Far East and Australsia"/>
  </Regions>

</Root>
__________________
Martin Honnen
Microsoft MVP - XML
My blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
nelly78 (October 23rd, 2009)
  #5 (permalink)  
Old October 23rd, 2009, 12:44 PM
Authorized User
Points: 156, Level: 3
Points: 156, Level: 3 Points: 156, Level: 3 Points: 156, Level: 3
Activity: 38%
Activity: 38% Activity: 38% Activity: 38%
 
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Thanks Martin. It is working as i wanted.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML to EXCEL ATTRIBUTE NOT WORKING pallone XSLT 4 September 7th, 2006 03:17 AM
Dynamic Linking in XML k_boatner BOOK: Beginning JavaScript 0 August 11th, 2006 03:46 PM
XML Attribute Ramkumar_VN ASP.NET 2.0 Professional 0 July 20th, 2006 10:07 AM
Linking opml/xml files to a html page helensobrien XML 0 February 21st, 2005 01:48 PM
Group XML by Attribute values? NotesSensei XSLT 4 July 14th, 2004 12:53 PM



All times are GMT -4. The time now is 04:12 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc