SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2001
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML / XML Schema Question

    Hello All,

    If anyone has any experience with XML Schema's I have a question for you.

    I wrote this XML:

    Code:
    <?xml version="1.0"?>
    <content xmlns="http://www.michaelsica.com"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.michaelsica.com content.xsd">
       <meta>
          <title>The Title</title>
          <author>Michael Sica</author>
          <date>2003-05-23</date>
       </meta>
       <item>
          <para id="1">
             Here is the first paragraph. 
             It contains a 
             <link address="http://www.google.com" title="Search  
             Engine">link</link> in the second sentence.
          </para>
          <para id="2">
             Here is the second paragraph. 
           <image  align="right">
           http://www.google.com/images/logo.gif</image> 
           It has an image in it. Aligned to the right.
          </para>
          <para id="3">
             Here is the third paragraph. It has both a 
             <link address="">link</link> and an 
              <image align="left">http://www.google.com/images/logo.gif</image> 
              image in it. But this image is aligned to the left. 
          </para>
       </item>
    </content>
    And I have been trying to write a schema for it. I run into trouble with the "para" tags because they are an element that contians other elements and character data. Here is the schema I wrote...

    Code:
    <?xml version="1.0"?>
    <xs:schema targetNamespace="http://www.michaelsica.com" 
               xmlns="http://www.michaelsica.com" 
               xmlns:xs="http://www.w3.org/2001/XMLSchema" 
               elementFormDefault="qualified">
       <xs:element name="content">
          <xs:complexType>
             <xs:sequence>
                <xs:element name="meta">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element name="title" type="xs:string"/>
                         <xs:element name="author" type="xs:string"/>
                         <xs:element name="date" type="xs:date"/>
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
                
                <xs:element name="item">
                   <xs:complexType>
                      <xs:sequence>
                      
                         <xs:element name="para" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType mixed="true">
                               <xs:sequence>                              
                                  <xs:any/>
                               </xs:sequence>                              
                               <xs:attribute name="id" type="xs:integer" use="required"/>
                            </xs:complexType>
                         </xs:element>
                         
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
                
             </xs:sequence>
          </xs:complexType>
       </xs:element>
    </xs:schema>
    I've tried using a couple of software packages (free trial of XMLSpy and a few others) and they all give me a warning that the "link" tag is used but not declared.

    Is this ok or do I have to do more?

    I tried using the following,

    Code:
    <xs:element name="link" minOccurs="0" maxOccurs="unbounded">
       <xs:complexType>
          <xs:simpleContent>
             <xs:extension base="xs:string">
                <xs:attribute name="address" type="xs:anyURI"/>
                <xs:attribute name="title" type="xs:string"/>
             </xs:extension>
          </xs:simpleContent>
       </xs:complexType>
    </xs:element>
    
    <xs:element name="image" minOccurs="0" maxOccurs="unbounded">
       <xs:complexType>
          <xs:simpleContent>
             <xs:extension base="xs:anyURI">
                <xs:attribute name="align" type="xs:string"/>
             </xs:extension>
          </xs:simpleContent>
       </xs:complexType>
    </xs:element>
    But if I put this inside an <xs:all> tag set then I can't have more than 1 occurence of the tags inside the "para" tag.

    Have I completly missed something?

    Thanks for any help,
    -michael.
    __________________________
    http://www.michaelsica.com

  2. #2
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Michael, I am too new at the XML to tell if something is missing. Try going to this site and by reading through and comparing your work, maybe you can catch what is wrong. http://www.w3.org/TR/2001/REC-xmlsch...0502/#concepts
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  3. #3
    SitePoint Zealot
    Join Date
    Aug 2001
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I've decided to crack open the O'Reilly "XML Schema" book and start from the beginning.
    __________________________
    http://www.michaelsica.com

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2001
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For anyone that cares...

    The line,

    Code:
    <xs:choice minOccurs="0" maxOccurs="unbounded">
    is what did it for me!

    Code:
    <?xml version="1.0"?>
    <xs:schema targetNamespace="http://www.michaelsica.com" 
               xmlns="http://www.michaelsica.com" 
               xmlns:xs="http://www.w3.org/2001/XMLSchema" 
               elementFormDefault="qualified">
       <xs:element name="content">
          <xs:complexType>
             <xs:sequence>
                <xs:element name="meta">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element name="title" type="xs:string"/>
                         <xs:element name="author" type="xs:string"/>
                         <xs:element name="date" type="xs:date"/>
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
                
                <xs:element name="item">
                   <xs:complexType>
                      <xs:sequence>
                      
                         <xs:element name="para" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType mixed="true">
                               <xs:choice minOccurs="0" maxOccurs="unbounded">    
                                                        
                                  <xs:element name="link" minOccurs="0" maxOccurs="unbounded">
                                     <xs:complexType>
                                        <xs:simpleContent>
                                           <xs:extension base="xs:string">
                                              <xs:attribute name="address" type="xs:anyURI"/>
                                              <xs:attribute name="title" type="xs:string"/>
                                           </xs:extension>
                                        </xs:simpleContent>
                                     </xs:complexType>
                                  </xs:element>
                                  
                                  <xs:element name="image" minOccurs="0" maxOccurs="unbounded">
                                     <xs:complexType>
                                        <xs:simpleContent>
                                           <xs:extension base="xs:anyURI">
                                              <xs:attribute name="align" type="xs:string"/>
                                           </xs:extension>
                                        </xs:simpleContent>
                                     </xs:complexType>
                                  </xs:element>
                                  
                               </xs:choice>
                               <xs:attribute name="id" type="xs:integer" use="required"/>
                            </xs:complexType>
                         </xs:element>
                         
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
                
             </xs:sequence>
          </xs:complexType>
       </xs:element>
    </xs:schema>
    __________________________
    http://www.michaelsica.com

  5. #5
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! glad you found the answer and then shared. Thanks for sharing.
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.




Bookmarks

Posting Permissions

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