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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How's my XML schema?

Status
Not open for further replies.

ITAmember

Technical User
Aug 16, 2010
3
US
It's my first time making an XML schema so I wanted to make sure I'm doing it right. Critiques and comments are more then welcome.

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

<xs:schema xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] targetNamespace="[URL unfurl="true"]http://www.w3schools.com"[/URL] xmlns="[URL unfurl="true"]http://www.w3schools.com"[/URL] elementFormDefault="qualified">

	<xs:complexType name="genreList">
		<xs:restriction base="xs:string">
			<xs:pattern value="a|b"/> <!--make comprehensive-->
		</xs:restriction>
	</xs:complexType>
	
	<xs:complexType name="languageList">
		<xs:restriction base="xs:string">
			<xs:pattern value="a|b"/> <!--make comprehensive-->
		</xs:restriction>
	</xs:complexType>

	<xs:element name="name"> <!--need a name for my new format-->
		<xs:complexType>
			<sequence>
				<xs:element name="album" maxOccurs="1">
					<xs:complexType>
						<xs:element name="metadata">
							<xs:complexType>
								<xs:sequence>
									<xs:element name="content"> <!--needs better name-->
										<xs:complexType>
											<xs:sequence>
												<xs:element name="title"    type="xs:string"/>
												<xs:element name="genre"    type="genreList"/>
												<xs:element name="year"     type="xs:integer"/>
												<xs:element name="bpm"      type="xs:integer"/>
												<xs:element name="length"   type="xs:time"/>
												<xs:element name="language" type="languageList"/>
											</xs:sequence>
										</xs:complexType>
									</xs:element>
									
									<xs:element name="involvedPersons">
										<xs:complexType>
											<xs:sequence>
												<xs:element name="artist"         type="xs:string"/>
												<xs:element name="accompaniment"  type="xs:string"/>
												<xs:element name="remix"          type="xs:string"/>
												<xs:element name="originalArtist" type="xs:string"/>
												<xs:element name="lyricist"       type="xs:string"/>
												<xs:element name="composer"       type="xs:string"/>
												<xs:element name="conductor"      type="xs:string"/>
												<xs:element name="musicianList"/>
													<xs:complexType>
														<xs:element name="person">
															<xs:complexType>
																<xs:element name="name"       type="xs:string" maxOccurs="1"/>
																<xs:element name="instrument" type="xs:string" maxOccurs="unbounded"/>
															</xs:complexType>
														</xs:element>
													</xs:complexType>
												<xs:element name="involvedList"  type="xs:string"/>
													<xs:complexType>
														<xs:element name="person">
															<xs:complexType>
																<xs:element name="name" type="xs:string" maxOccurs="1"/>
																<xs:element name="role" type="xs:string" maxOccurs="unbounded"/>
															</xs:complexType>
														</xs:element>
													</xs:complexType>
												<xs:element name="encodedBy"      type="xs:string"/>
											</xs:sequence>
										</xs:complexType>
									</xs:element>
									
									<xs:element name="pictures" minOccurs="0"> <!--force PNG?-->
										<xs:complexType>
											<xs:sequence>
												<xs:element name="frontCover"        type="base64Binary" minOccurs="0"/>
												<xs:element name="backCover"         type="base64Binary" minOccurs="0"/>
												<xs:element name="fileIcon"          type="base64Binary" minOccurs="0"/>
												<xs:element name="leafletPage"       type="base64Binary" minOccurs="0"/>
												<xs:element name="media"             type="base64Binary" minOccurs="0"/>
												<xs:element name="leadArtist"        type="base64Binary" minOccurs="0"/>
												<xs:element name="artist"            type="base64Binary" minOccurs="0"/>
												<xs:element name="conductor"         type="base64Binary" minOccurs="0"/>
												<xs:element name="accompaniment"     type="base64Binary" minOccurs="0"/>
												<xs:element name="composer"          type="base64Binary" minOccurs="0"/>
												<xs:element name="lyricist"          type="base64Binary" minOccurs="0"/>
												<xs:element name="recordingLocation" type="base64Binary" minOccurs="0"/>
												<xs:element name="recording"         type="base64Binary" minOccurs="0"/>
												<xs:element name="performance"       type="base64Binary" minOccurs="0"/>
												<xs:element name="illustration"      type="base64Binary" minOccurs="0"/>
												<xs:element name="artistLogotype"    type="base64Binary" minOccurs="0"/>
												<xs:element name="publisherLogotype" type="base64Binary" minOccurs="0"/>
												
												
											</xs:sequence>
										</xs:complexType>
									</xs:element>
								</xs:sequence>
							</xs:complexType>
						</xs:element>
					</xs:complexType>
				</xs:element>

				<xs:element name="track" maxOccurs="unbounded">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="number" type="xs:integer"/>
							<xs:element name="title"  type="xs:string" />
							<xs:element name="file">
								<xs:complexType>
									<xs:sequence>
										<xs:element name="name"  type="xs:string" minOccurs="0"/>
										<xs:element name="start" type="xs:string" minOccurs="0"/> <!--MSF-->
										<xs:element name="break" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <!--MSF-->
										<xs:element name="end"   type="xs:string" minOccurs="0"/> <!--MSF-->
									</xs:sequence>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</sequence>
		</xs:complexType>
	</xs:element>

</xs:schema>
 
[0] Add a version to xs:schema.
[1] base64Binary data type belongs to schema namespace, it should be read xs:base64Binary.
[2] xs:element musicianList and involvedList are not meant to be empty. They should wrap around the xs:complexType following them.
[3] sequence is in xs namespace. It should be read xs:sequence. (This happened right under xs:element name.)
[4] xs:complexType should not be followed directly by xs:element. There should be some model group element, such as xs:sequence, that is what I think you meant. (These happened near the musicianList and involveList.)
 
Thank you!

A couple more questions:

How do I edit my post? (I would like to add the updated schema there vs making this thread huge) I don't see an edit button anywhere.

Is 0.01 Ok for the schema version? All the examples I've seen have been in the X.X format but I will go though a lot of revisions before the big 1.0 release.

How much filesize overhead will xs:base64Binary have?

How would I make a type in the M:S:F format where M is a number from 0 to infinity, S is a number from 0 to 59, and F is a number from 0 to 74? It looks like I need a weird combination of xs:pattern and xs:maxInclusive/xs:minInclusive.


Once again, thank you for your help.
 
Q1:>How do I edit my post?
A1: You do not do that here.

Q2:>Is 0.01 Ok for the schema version?
A2: The version in question is the version of the w3c xml schema used. It should be [tt]version="1.0"[/tt] (unless you want to use 1.1 now available but the use and support are not wide-spread yet.)

Q3:>How much filesize overhead will xs:base64Binary have?
A3: Without being academic, 6 bits of binary are mapped to 8-bit character code. Hence an expansion of 3:4, plus some contingent minor overhead of paddings and line breaks.

Q4:>How would I make a type in the M:S:F format where M is a number from 0 to infinity, S is a number from 0 to 59, and F is a number from 0 to 74?
A4: Something like this in the restriction pattern.
[tt] <xs:pattern value="(0|[1-9][0-9]*):([0-9]|[1-4][0-9]|5[0-9]):([0-9]|[1-6][0-9]|7[0-4])" />[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top