Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2006, 03:59 AM
Authorized User
 
Join Date: Apr 2006
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
 
Old April 27th, 2006, 04:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old April 30th, 2006, 12:48 AM
Authorized User
 
Join Date: Apr 2006
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
 
Old April 30th, 2006, 06:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old April 30th, 2006, 06:47 AM
Authorized User
 
Join Date: Apr 2006
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
 
Old April 30th, 2006, 10:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old May 1st, 2006, 06:24 AM
Authorized User
 
Join Date: Apr 2006
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
 
Old May 1st, 2006, 06:36 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old May 1st, 2006, 07:42 AM
Authorized User
 
Join Date: Apr 2006
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.