XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old April 6th, 2008, 09:50 PM
josteen josteen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 36 josteen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 39 m 34 sec
Reputation Power: 1
Should be a simple problem for someone

Ok I am creating a schema for an XML document that manages an inventory for a CD distributor.

The XML is pretty simple...

Code:
<inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="music.xsd">
   <album category="Modern" albumID="JW1234">
           <title>The Noise We Make</title>
           <artist>Chris Tomlin</artist>
           <tracks length="00:49:05">
               <track length="00:04:22">The Noise We Make</track>
               <track length="00:05:13">Forever</track>
               <track length="00:04:21">Kindness</track> 
               <track length="00:04:48">America</track> 
               <track length="00:07:08">The Wonderful Cross</track> 
               <track length="00:04:26">Captured</track> 
               <track length="00:03:52">Be Glorified</track> 
               <track length="00:03:18">Happy Song</track> 
               <track length="00:04:05">Need You Now</track> 
               <track length="00:05:35">This is Our God</track> 
               <track length="00:03:57">Forever (radio remix)</track> 
           </tracks>
   </album>
</inventory>


I have all of my schema down except one part I am very confused about. When I'm defining my <tracks> as a complex datatype I have the element <track> in it as the XML does; however, <track> is also it's own complex datatype because it has an attribute [length]. How would you do this part of the schema because the way I have it gets an error because the element <track> is used to often; because it's both in my TracksType and Tracktype complex datatype definitions. Any help would be very much appreciated. Thanks!


Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!-- definition of simple types -->

  <xs:simpleType name="nameType">
    <xs:restriction base="xs:string">
      <xs:maxLength value="32"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="lengthType">
    <xs:restriction base="xs:string">
      <xs:pattern value="\d{2}:\d{2}:\d{2}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="albumIDType">
    <xs:restriction base="xs:string">
      <xs:pattern value="JW\d{4}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="categoryType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Swing"/>
      <xs:enumeration value="Modern"/>
      <xs:enumeration value="Hip Hop"/>
    </xs:restriction>
  </xs:simpleType>


	
  <!-- definition of complex types -->
   <xs:complexType name="trackType">
   <xs:element name="track" type="nameType"/>  
   <xs:attribute name="length" type="lengthType" use="optional"/>
   </xs:complexType>

  <xs:complexType name="tracksType">
   <xs:sequence>
     <xs:element name="track" type="trackType" minOccurs="1" maxOccurs="unbounded"/>        <!-- the definition of the "track" element is
          using the "trackType" complex type    -->	
   </xs:sequence>
   <xs:attribute name="length" type="lengthType" use="optional"/>
  </xs:complexType>

  <xs:complexType name="albumType">
    <xs:sequence>
      <xs:element name="title" type="nameType"/>
      <xs:element name="artist" type="nameType" minOccurs="1" maxOccurs="unbounded"/>
      <xs:element name="tracks" type="tracksType"/>
      <!-- the definition of the "tracks" element is
        using the "tracksType" complex type    -->	
    </xs:sequence>
    <xs:attribute name="category" type="categoryType" use="required"/>
    <xs:attribute name="albumID" type="albumIDType" use="required"/>
  </xs:complexType>

  <xs:complexType name="inventoryType">
    <xs:sequence>
      <xs:element name="album" type="albumType"/>
      <!-- the definition of the "album" element is
        using the "albumType" complex type    -->
    </xs:sequence>
  </xs:complexType>
  
  <!-- Reference to "inventoryType" to define the
     "inventory" element -->
  <xs:element name="inventory" type="inventoryType"/>

</xs:schema>

Reply With Quote
  #2  
Old April 7th, 2008, 10:03 AM
jkmyoung jkmyoung is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 474 jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level)jkmyoung User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 m 31 sec
Reputation Power: 52
Easiest way to fix it would probably be:
Code:
<xs:complexType name="trackType" mixed="true">
	<xs:attribute name="length" type="lengthType" use="optional"/>
</xs:complexType>

Reply With Quote
  #3  
Old April 7th, 2008, 01:25 PM
josteen josteen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 36 josteen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 39 m 34 sec
Reputation Power: 1
Quote:
Originally Posted by jkmyoung
Easiest way to fix it would probably be:
Code:
<xs:complexType name="trackType" mixed="true">
	<xs:attribute name="length" type="lengthType" use="optional"/>
</xs:complexType>


Yes you are correct. I didn't understand what my textbook was saying about Mixed content. I bought a new book this morning and read their section on Mixed content and it made perfect sense. Your example worked perfectly. Thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Should be a simple problem for someone


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway