www.webdeveloper.com
Results 1 to 2 of 2

Thread: Schema and namespaces

Hybrid View

  1. #1
    Join Date
    May 2011
    Posts
    4

    Schema and namespaces

    Hi!
    I am looking at namespaces and Schema files. I have this sample XML file:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="cdcol.xsl"?>
    <cdcollection
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://mywebspace.org/mycds" 
    xsi:schemaLocation="http://mywebspace.org/mycds cdcol-alt.xsd">
      <!-- Start cd collection -->
      <cd id="ABC:1"> 
        <titel>Beauty</titel>
        <artist>Ryuichi Sakamoto</artist>
        <released>1990</released>
        <price>15.00</price>
      </cd>
      <cd id="BCD:85734965239852">
        <titel>Goodbye Country (Hello Nightclub)</titel>
        <artist>Groove Armada</artist>
        <released>2001</released>
        <price>45.00</price>
      </cd>
      <cd id="AER:3">
        <titel>Glee</titel>
        <artist>Bran Van 3000</artist>
        <released>1997</released>
        <price>95.00</price>
      </cd>
      <cd id="APO:4">
        <titel>Pyramid</titel>
        <artist>Alan Parsons Project</artist>
        <released>1978</released>
        <price>65.00</price>
      </cd>
      <cd id="AVD:5">
        <titel>Tales of Mystery and Imagination</titel>
        <artist>Alan Parsons Project</artist>
        <released>1976</released>
        <price>55.00</price>
      </cd>
      <cd id="LYT:0000">
        <titel>Gaudi</titel>
        <artist>Alan Parsons Project</artist>
        <released>1989</released>
        <price>35.00</price>
      </cd>
    </cdcollection>
    and a corresponding Schema file:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema targetNamespace="http://mywebspace.org/mycds" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns="http://mywebspace.org/mycds"
     elementFormDefault="qualified">
    	<!-- Simple elements -->
    	<xs:group name="cdinfogroup">
    	<xs:sequence>
    	<xs:element name="titel" type="xs:string" />
    	<xs:element name="artist" type="xs:string" />
    	<xs:element name="released" type="notOld" />
    	<xs:element name="price" type="xs:decimal" />
    	</xs:sequence>
    	</xs:group>
    	
    	<!-- Attributes -->
    	<xs:attribute name="id">
    	<xs:simpleType>
    	<xs:restriction base="xs:string">
    	<xs:pattern value="[A-Z]{3}:\d+" />
    	</xs:restriction>
    	</xs:simpleType>
    	</xs:attribute>
    
    	<!-- Types -->
    	<xs:simpleType name="notOld">
    	<xs:restriction base="xs:gYear">
    	<xs:minExclusive value="1900" />
    	</xs:restriction>
    	</xs:simpleType>
    	
    	<!-- Complex Elements -->
    	<xs:element name="cd">
    	<xs:complexType>
    	<xs:sequence>
    	<xs:group ref="cdinfogroup" />
    	</xs:sequence>
    	<xs:attribute ref="id" use="required" />
    	</xs:complexType>
    	</xs:element>
    	
    	<!-- Root element -->
    	<xs:element name="cdcollection">
    	<xs:complexType>
    	<xs:sequence>
    	<xs:element ref="cd" minOccurs="1" maxOccurs="unbounded" />
    	</xs:sequence>
    	</xs:complexType>
    	</xs:element>
    </xs:schema>
    Without any mention of the namespace: http://mywebspace.org/mycds in any of the files it works fine. But I am doing something wrong declaring the namespace in the Schema file. Does someone see what I do wrong? Validators complain about the "id" attribute. if I make elementFormDefault unqualified it complains about the cd element and the id attribute

    I'm greatful for a quick response :-).

    /T

  2. #2
    Join Date
    May 2011
    Posts
    4
    No one?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles