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

XML / XSD Validation Issue

Status
Not open for further replies.

icu222much

Technical User
Mar 12, 2007
26
0
0
CA
I've created a XML + Schema and am trying to validate it but I keep on receiving errors that I do not understand. I believe I have done what w3schools has done, but for some reason it is not valid.

XML
Code:
<collection  xmlns="[URL unfurl="true"]http://www.w3schools.com"[/URL] 
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] 
xsi:schemaLocation="mallSchema.xsd">

XSD
Code:
<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">

One record of XML doc

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="mallLayout.xsl"?>


<collection 
xmlns="[URL unfurl="true"]http://www.w3schools.com"[/URL]
xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL]
xsi:schemaLocation="mallSchema.xsd">


	<mall>
		<title>Aberdeen</title>
		<hours>
			<daysOfTheWeek>Mon-Wed</daysOfTheWeek>
			<hoursEachDay>11am-7pm</hoursEachDay>
		</hours>
		<hours>
			<daysOfTheWeek>Thu-Sat</daysOfTheWeek>
			<hoursEachDay>11am-9pm</hoursEachDay>
		</hours>
		<hours>
			<daysOfTheWeek>Sun&amp;Holi</daysOfTheWeek>
			<hoursEachDay>11am-7pm</hoursEachDay>
		</hours>
		<address>
			<street>4151 Hazelbridge Way</street>
			<city>Richmond</city>
		</address>
		<phone>604.270.1234</phone>
		<website url="[URL unfurl="true"]http://www.aberdeencentre.com">www.aberdeencentre.com</website>[/URL]
		<description>When we built Aberdeen Centre back in 1989, our goal was to create the first truly Asian shopping experience in the Lower Mainland. Our success has inspired us to look beyond cultures, to re-imagine and redefine a new type of retail and entertainment experience. One that embraces the best of East and West. A celebration of multiculturalism. To achieve this we are building a state-of-the-art shopping and entertainment complex triple the size of the original. My vision for the new Aberdeen Centre is to see it become Greater Vancouver pre-eminent cosmopolitan shopping destination. The first Asian/Western centre of its kind, anywhere.</description>
		<dateSubmitted>September 20, 2011</dateSubmitted>
		<coordinates lat="49.183445" lon="-123.133424"/>
		<mainPhoto>[URL unfurl="true"]http://www.sfu.ca/~jca41/iat352/assignment/01/img/aberdeen.jpg</mainPhoto>[/URL]
		<photo id="5318145511" urlT="[URL unfurl="true"]http://farm6.static.flickr.com/5082/5318145511_0c53c48f3b_t.jpg"[/URL] widthT="100" heightT="67" urlM="[URL unfurl="true"]http://farm6.static.flickr.com/5082/5318145511_0c53c48f3b.jpg"[/URL] widthM="500" heightM="333" lat="49.183445" lon="-123.133424" />
		<photo id="2126379146" urlT="[URL unfurl="true"]http://farm3.static.flickr.com/2384/2126379146_3295fcba83_t.jpg"[/URL] widthT="75" heightT="100" urlM="[URL unfurl="true"]http://farm3.static.flickr.com/2384/2126379146_3295fcba83.jpg"[/URL] widthM="375" heightM="500" lat="49.183445" lon="-123.133424" />
		<photo id="2710310345" urlT="[URL unfurl="true"]http://farm4.static.flickr.com/3207/2710310345_4ecec6cb81_t.jpg"[/URL] widthT="100" heightT="75" urlM="[URL unfurl="true"]http://farm4.static.flickr.com/3207/2710310345_4ecec6cb81.jpg"[/URL] widthM="500" heightM="375" lat="49.183445" lon="-123.133424" />
		<photo id="2710310277" urlT="[URL unfurl="true"]http://farm4.static.flickr.com/3069/2710310277_c63e2684e5_t.jpg"[/URL] widthT="100" heightT="75" urlM="[URL unfurl="true"]http://farm4.static.flickr.com/3069/2710310277_c63e2684e5.jpg"[/URL] widthM="500" heightM="375" lat="49.183445" lon="-123.133424" />
		<photo id="2711122722" urlT="[URL unfurl="true"]http://farm4.static.flickr.com/3150/2711122722_1eef09103e_t.jpg"[/URL] widthT="100" heightT="75" urlM="[URL unfurl="true"]http://farm4.static.flickr.com/3150/2711122722_1eef09103e.jpg"[/URL] widthM="500" heightM="375" lat="49.183445" lon="-123.133424" />
	</mall>
	
	


</collection>

Entire XSD doc

Code:
<?xml version ="1.0"?>

<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:element name="collection">
<xs:complexType>
<xs:sequence> 

	<xs:element name="mall">
		<xs:complexType>
			<xs:sequence>
			
				<xs:element name="title" type="xs:string" />
				
				<xs:element name="hours">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="daysOfTheWeek" type="xs:string" />
							<xs:element name="hoursEachDay" type="xs:string" />	
						</xs:sequence>
					</xs:complexType>
				</xs:element>
						
				<xs:element name="address">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="street" type="xs:string" />
							<xs:element name="city" type="xs:string" />	
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				
				<xs:element name="phone" type="xs:string" />
				
				<xs:element name="website">
					<xs:complexType>
						<xs:attribute name="url" type="xs:string" />
					</xs:complexType>
				</xs:element>
				
				
				<xs:element name="description">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:minLength value="300"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>

				
				<xs:element name="dateSubmitted" type="xs:string" />
				
				<xs:element name="coordinates">
					<xs:complexType>
						<xs:attribute name="lat" type="xs:string" use="required" />
						<xs:attribute name="lon" type="xs:string" use="required" />
					</xs:complexType>
				</xs:element>
				
				<xs:element name="mainPhoto" type="xs:string" />
				
				<xs:element name="photo">
					<xs:complexType>
						<xs:attribute name="id" type="xs:string" use="required" />
						<xs:attribute name="urlT" type="xs:string" use="required" />
						<xs:attribute name="widthT" type="xs:string" use="required" />
						<xs:attribute name="heightT" type="xs:string" use="required" />
						<xs:attribute name="urlM" type="xs:string" use="required" />
						<xs:attribute name="widthM" type="xs:string" use="required" />
						<xs:attribute name="heightM" type="xs:string" use="required" />
						<xs:attribute name="lat" type="xs:string" use="required" />
						<xs:attribute name="lon" type="xs:string" use="required" />
					</xs:complexType>
				</xs:element>
			
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
</xs:sequence>
</xs:complexType>
</xs:element>	
	
</xs:schema>
 
Error in XML document:

8:37 - SchemaLocation: schemaLocation value = 'mallSchema.xsd' must have even number of URI's.

8:37 - cvc-elt.1: Cannot find the declaration of element 'collection'.


Error in XML document:

4:65 - argetNamespace.2: Expecting no namespace, but the schema document has a target namespace of '
 
First one is very clear, isn't it? You need to parameters for schemaLocation as shown here.



Cheers,
Dian
 
Didn't I provide the schemaLocation by saying xsi:schemaLocation="mallSchema.xsd" ?

I don't understand the second error either as I already declared <xs:element name="collection"> in my schema.

For the third point, I just copied what I found online at W3Schools, and I still receive an error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top