Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 27th, 2006, 03:59 AM
Authorized User
 
Join Date: Apr 2006
Location: omer, israel, Israel.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kfir
Default elements with same name

hello

I am writing a code that has 2 elements with the same name (example below). I need to keep both the elements, but each one to be with some of the attributes (the attributes will be divided to 2 groups).
the element data is called from 2 different parents. how can I make the different that each element will be called to his correct parent?
(I dont want to exchange the hirarchy)

<xs:element name="data">
- <xs:complexType>
  <xs:attribute name="class" use="required" type="xs:NCName" />
  <xs:attribute name="collection-id" use="required" type="xs:NCName" />
  <xs:attribute name="dbcolumn" type="xs:NCName" />
  <xs:attribute name="func" type="xs:NCName" />
  <xs:attribute name="last-summary" type="xs:NCName" />
  <xs:attribute name="mandatory" use="required" type="xs:NCName" />
  <xs:attribute name="type" use="required" type="xs:NCName" />
  </xs:complexType>
  </xs:element>


thanks

kfir
__________________
kfir
Reply With Quote
  #2 (permalink)  
Old April 27th, 2006, 04:17 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If the element declarations are local (<xs:element name="x" defined within an <xs:complexType>) then there is no problem having two elements with the same name but different content models. If you want to reuse attribute definitions or other parts of the content model you can do this by extending an abstract base type that contains the shared defintions, or you can use named attribute groups.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old April 30th, 2006, 12:48 AM
Authorized User
 
Join Date: Apr 2006
Location: omer, israel, Israel.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kfir
Default

I will Rephrase the Q.
I have 2 elements, with different attributes. each element has a different father. my Q, is how exactly I can write the code that it will recieve both the elements with the same name (both the elements are not local.
here is what I mean in example if I wasn’t written the Q correctly:
xml file:
<etd version="">
   <entities>
      <entity eid="" tid="" plural-tid="" grouping-tid="" plural-grouping-tid="" length="">
         <data class="" type="" dbcolumn="" mandatory="" last-summary="" collection-id="" />
      </entity>
   </entities>
   <counters>
      <counter tid="">
         <data class="" type="" dbcolumn="" mandatory="" func="" collection-id="" />
      </counter>
   </counters>
</etd>

my Q again, is how do I write the code that It will be able to recognize the data attribute for each parent (if it is counter or entity.).
thank you very much.
kfir


kfir
Reply With Quote
  #4 (permalink)  
Old April 30th, 2006, 06:37 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

What language are you writing the code in? Java, VB_Script, XSLT, XQuery?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old April 30th, 2006, 06:47 AM
Authorized User
 
Join Date: Apr 2006
Location: omer, israel, Israel.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kfir
Default

I write the it in xsd schema. what I gave is part of the xml file that I am building the schema to.

kfir
Reply With Quote
  #6 (permalink)  
Old April 30th, 2006, 10:12 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

OK, I thought it must be something different, because in that case my first answer covers it. The two elements entity and counter have different complex types, each of these complex types must include a local element declaration for data, and the two data elements define different sets of attributes.

Other possibilities are (a) redesign the document to avoid overloading the element name, or (b) recognize that you can't always validate everything in XML Schema - there will always be some constraints that have to be checked procedurally.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old May 1st, 2006, 06:24 AM
Authorized User
 
Join Date: Apr 2006
Location: omer, israel, Israel.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kfir
Default

do you maybe have an example of how to write it, or a good website that has an examples of how to write it?

thanks


kfir
Reply With Quote
  #8 (permalink)  
Old May 1st, 2006, 06:36 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know any good online tutorial sites for XML Schema. It's a complicated language and I wouldn't advise anyone to try and write schemas without first buying and studying a good book on the subject. Even though this is a Wrox site, I would be inclined first to recommend Eric van der Vlist (O'Reilly) or Priscilla Walmsley (prenticec-Hall).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #9 (permalink)  
Old May 1st, 2006, 07:42 AM
Authorized User
 
Join Date: Apr 2006
Location: omer, israel, Israel.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kfir
Default

I am trying to write for each element, to define type (for example:<xs:element name="display" type="entity-display" />)
I am encounter a problems:
1. if I will write another element with the same name but different type, it will shout that there are 2 elements with same name, no matter if it is other types.

I will appreciate if some one could give me an example how to write in a schema from this code example, how to make it valid that for each data element I will be able to give different attributes for each parent:


<etd version="">
   <entities>
      <entity eid="" tid="" plural-tid="" grouping-tid="" plural-grouping-tid="" length="">
         <data class="" type="" dbcolumn="" mandatory="" last-summary="" collection-id="" />
      </entity>
   </entities>
   <counters>
      <counter tid="">
         <data class="" type="" dbcolumn="" mandatory="" func="" collection-id="" />
      </counter>
   </counters>

waiting for an answer for whom ever can help me, I am kind of stuck.
thanks

kfir
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning elements. Neal XSLT 2 May 13th, 2007 04:38 PM
help in selecting elements spandit XSLT 1 April 9th, 2007 07:27 PM
Selecting elements up until a certain one Frode XSLT 5 January 19th, 2006 01:22 PM
elements to attribute value samedan XSLT 0 July 4th, 2005 11:05 AM
Restrict elements guozhang XML 0 April 28th, 2004 02:26 PM



All times are GMT -4. The time now is 03:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.