Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to understand russian doll, simple types and complex types...

Status
Not open for further replies.

BoulderNative

IS-IT--Management
Aug 7, 2011
3
US
Hi,

I am new to XML and am struggling to understand some elemental concepts relating to XML. I am working to learn namespaces and how to nest simpleTypes and complexTypes in a Russian Doll format. I have been researching the internet and several books I have in my possession to see if I can find the answers, and I just seem to be getting more confused/going in circles. I am wondering if someone could offer some assistance.

This is my xml file:

<?xml version="1.0" encoding="UTF-8"?>


<inventory xsi:noNamespaceSchemaLocation="music.xsd"
xmlns:xsi="

<album category="Modern" albumID="JW001305">
<title>Kind of Blue</title>
<artist>Miles Davis</artist>
<artist>John Coltrane</artist>z
<tracks length="0:45:44">
<track length="0:9:22">So What</track>
<track length="0:9:46">Freddie Freeloader</track>
<track length="0:5:37">Blue in Green</track>
<track length="0:11:33">All Blues</track>
<track length="0:9:26">Flamenco Sketches</track>
</tracks>
</album>
<album category="Bebop" albumID="JW001312">
<title>Cookin'</title>
<artist>Miles Davis</artist>
<tracks length="0:35:13">
<track length="0:5:57">My Funny Valentine</track>
<track length="0:9:53">Blues by Five</track>
<track length="0:4:22">Airegin</track>
<track length="0:13:03">Tune-Up</track>
</tracks>
</album>
<album category="Modern" albumID="JW015011">
<title>Blue Train</title>
<artist>John Coltrane</artist>
<tracks length="0:41:54">
<track length="0:10:39">Blue Train</track>
<track length="0:9:06">Moment's Notice</track>
<track length="0:7:11">Locomotion</track>
<track length="0:7:55">I'm Old Fashioned</track>
<track length="0:7:03">Lazy Bird</track>
</tracks>
</album>

</inventory>

***EOF***

This is my .xsd file:

<?xml version="1.0" encoding="UTF-8"?>


<xsi:schema xmlns:xsi="
<xsi:simpleType name="albumIDType" >
<xsi:restriction base="xsi:ID" >
<xsi:pattern value="JW######" />
</xsi:restriction>
</xsi:simpleType>

<xsi:simpleType name="jazzType" >
<xsi:restriction base="xsi:string" >
<xsi:enumeration value="New_Orleans" />
<xsi:enumeration value="Swing" />
<xsi:enumeration value="Bebop" />
<xsi:enumeration value="Modern" />
</xsi:restriction>
</xsi:simpleType>

<xsi:element name="inventory" >
<xsi:complexType>
<xsi:element name="album" minOccurs="1" maxOccurs="unbounded" />
<xsi:complexType>
<xsi:sequence>
<xsi:element name="title" type="xsi:string" />
<xsi:element name="artist" type="xsi:string" minOccurs="1" maxOccurs="unbounded" />
<xsi:element name="tracks" />
<xsi:complextype>
<xsi:simpleContent>
<xsi:extension base="xsi:time">
<xsi:attribute name="length" type="xsi:time" />
<xsi:complexType>
<xsi:element name="track" type="xsi:string" minOccurs="1" maxOccurs="unbounded"/> <xsi:complextype>
<xsi:simpleContent>
<xsi:extension base="xsi:time">
<xsi:attribute name="length" type="xsi:time" />
</xsi:extension>
</xsi:simpleContent>
</xsi:complextype>
</xsi:complexType>
</xsi:extension>
</xsi:simpleContent>
</xsi:complextype>
<xsi:attribute name="category" type="jazzType" />
<xsi:attribute name="albumID" type="albumIDType" />
</xsi:sequence>
</xsi:complexType>
</xsi:complexType>
</xsi:element>
</xsi:schema>


***EOF***

The XML file will not validate. Here is the error message I am getting:

[Xerces-J 2.9.1] Validating "jw.xml" against "file:/C:/Documents and Settings/Phil/My Documents/Education/MCT_617/Week 5 Homework/c4_case_1/music.xsd" ...
Ln 35 Col 70 - s4s-elt-invalid-content.1: The content of '#AnonType_inventory' is invalid. Element 'element' is invalid, misplaced, or occurs too often.
1 Errors


Any pointers or tips in helping me understand what I am doing wrong here would be appreciated...
 
Sorry, please disregard this post as I did not see the policy regarding no students. This kind of stinks though because I can't get my instructor to respond to me, and I have really been doing everything I can to understand the problem with my code on my own. Essentially I have acted within the spirit and intent of the no-students policy in that I have done most of the work, and have not asked anyone to complete my work for me. I just need some direction, and I can't get the help I need from the person who is supposed to help me.

What am I supposed to do in this case?
 
Acting in a professional and courteous manner works!

I used StylusStudio on your documents and got the following:
[tt]Validating music.xml...
file:///c:/Users/ThomasM/Desktop/Test/music.xsd:23,67: Invalid child 'element' in the complex type
file:///c:/Users/ThomasM/Desktop/Test/music.xml:8,4: No character data is allowed by content model
file:///c:/Users/ThomasM/Desktop/Test/music.xml:8,48: Unknown element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:8,48: Attribute 'category' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:8,48: Attribute 'albumID' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:20,4: No character data is allowed by content model
file:///c:/Users/ThomasM/Desktop/Test/music.xml:20,47: Unknown element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:20,47: Attribute 'category' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:20,47: Attribute 'albumID' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:30,4: No character data is allowed by content model
file:///c:/Users/ThomasM/Desktop/Test/music.xml:30,48: Unknown element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:30,48: Attribute 'category' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:30,48: Attribute 'albumID' is not declared for element 'album'
file:///c:/Users/ThomasM/Desktop/Test/music.xml:42,1: No character data is allowed by content model
file:///c:/Users/ThomasM/Desktop/Test/music.xml:42,13: Element 'album' is not valid for content model: 'EMPTY'[/tt]

Perhaps this will help? I am not an expert on XML Schema, and this is your work... I would point out that the first diagnostic pertains directly to the structure of the schema itself, and then the others, diagnosing those parts of the XML document that are not schema valid, indicate that the document the schema describes is not the document you want to describe.

Happy hunting!

Tom Morrison
Micro Focus
 
One web resource I find useful is W3Schools. Their treatment of complex type definition may be found here.

Tom Morrison
Micro Focus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top