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 January 16th, 2007, 02:42 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add attribute to unbounded element

I have the following snippet of schema.

Please note "abc" is my namespace.

<xs:complexType name=AddresseeType">
  <xs:sequence>
      <xs:element name="Severity" type="xs:string"/>
      <xs:element name="Name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="ToType">
   <xs:sequence>
     <xs:element name="to" type="abc:AddresseeType" maxOccurs="unbounded"/>
   </xs:sequence>
</xs:complexType>

<xs:complexType name="CcType">
   <xs:sequence>
     <xs:element name="copy" type="abc:AddresseeType" maxOccurs="unbounded"/>
   </xs:sequence>
</xs:complexType>

I like to insert "xyz" attribute to the "to" element, which is unbounded, in the "ToType". This is my "xyz" attribute I like to insert.

<xs:attribute name="xyz" type="xs:boolean" default="true"/>

This is what I have so far on the "ToType":

<xs:complexType name="ToType">
   <xs:sequence>
     <xs:element name="to" type="abc:AddresseeType" maxOccurs="unbounded">
         <xs:complexType>
            <xs:attribute name="xyz" type="xs:boolean" default="true"/>
         </xs:complexType>
     </xs:element>
   </xs:sequence>
</xs:complexType>

I have trouble inserting the "xyz" attribute to the "to" element. Please help.

Please note that the "copy" element in the "CcType" also uses the "AddresseeType", so I don't want to make changes to the "AddresseeType".

Appreciate any help.

 
Old January 16th, 2007, 03:16 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want something like:

<xs:element name="to">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="abc:AddressType">
         <xs:attribute name="xyz" type="xs:boolean" default="true"/>
      </
    </
  </
</

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 16th, 2007, 03:27 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your quick response.

How do I put "unbounded" in your suggested code, because I like to have the "to" element to be unbounded?

 
Old January 16th, 2007, 03:30 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind. I just figure it out.

 
Old January 16th, 2007, 03:42 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xs:complexType name="ToType">
   <xs:sequence>
     <xs:element name="to" maxOccurs="unbounded">
       <xs:complexType>
         <xs:complexContent>
           <xs:extension base="abc:AddressType">
             <xs:attribute name="xyz" type="xs:boolean"
                           default="true"/>
           </
         </
       </
     </xs:element>
   </xs:sequence>
</xs:complexType>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add an attribute to each element bartnowa XSLT 3 November 8th, 2007 12:12 PM
value-of within the HTML element attribute BrendonMelville XSLT 1 March 14th, 2006 11:32 AM
Attribute for first element only mehdi62b XML 1 January 2nd, 2006 06:26 AM
How to add search functionality to unbounded form? method Access VBA 4 June 24th, 2005 06:40 AM
How can I get the element node of an attribute cdias XSLT 2 March 15th, 2004 10:34 AM





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