Link to home
Start Free TrialLog in
Avatar of catonthecouchproductions
catonthecouchproductionsFlag for United States of America

asked on

XML Validation Issue

I am having trouble getting the XML file to validate.

I believe the error is coming because "Parts" requires the attribute Qty, when I need it to be required on the Part element.

Anyone have any ideas?
grills.xml
----
<?xml version="1.0" ?>
<!-- Grills Sold by GrillRite -->
 
<grl:Grills xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:grl="http://grillrite.com/grills"
     xsi:schemaLocation="http://grillrite.com/grills GRSchema.xsd">
   <Model>
      <Name>Standard</Name>
      <Price>$96.50</Price>
      <InStock>302</InStock>
      <Parts>
         <Part Qty="1">Main Burner</Part>
         <Part Qty="1">Standard Chassis</Part>
         <Part Qty="1">Controls</Part>
         <Part Qty="1">Gas Tubing</Part>
         <Part Qty="1">Igniter</Part>
         <Part Qty="1">Main Rack</Part>
         <Part Qty="1">Stand</Part>
      </Parts>
   </Model>
   <Model>
      <Name>Deluxe</Name>
      <Price>$105.15</Price>
      <InStock>299</InStock>
      <Parts>
         <Part Qty="1">Main Burner</Part>
         <Part Qty="1">Standard Chassis</Part>
         <Part Qty="2">Controls</Part>
         <Part Qty="1">Gas Tubing</Part>
         <Part Qty="1">Igniter</Part>
         <Part Qty="1">Main Rack</Part>
         <Part Qty="1">Top Rack</Part>
         <Part Qty="1">Stand</Part>
      </Parts>
   </Model>
   <Model>
      <Name>Dual</Name>
      <Price>$155.20</Price>
      <InStock>100</InStock>
      <Parts>
         <Part Qty="1">Main Burner</Part>
         <Part Qty="1">Side Burner</Part>
         <Part Qty="1">Extended Chassis</Part>
         <Part Qty="2">Controls</Part>
         <Part Qty="2">Gas Tubing</Part>
         <Part Qty="2">Igniter</Part>
         <Part Qty="1">Main Rack</Part>
         <Part Qty="1">Side Rack</Part>
         <Part Qty="2">Top Rack</Part>
         <Part Qty="1">Stand</Part>
      </Parts>
   </Model>
   <Model>
      <Name>Extended</Name>
      <Price>$178.00</Price>
      <InStock>311</InStock>
      <Parts>
         <Part Qty="1">Main Burner</Part>
         <Part Qty="2">Side Burner</Part>
         <Part Qty="1">Extended Chassis</Part>
         <Part Qty="3">Controls</Part>
         <Part Qty="3">Gas Tubing</Part>
         <Part Qty="3">Igniter</Part>
         <Part Qty="1">Main Rack</Part>
         <Part Qty="2">Side Rack</Part>
         <Part Qty="2">Top Rack</Part>
         <Part Qty="1">Stand</Part>
      </Parts>
   </Model>
</grl:Grills>
 
 
 
 
 
-------------
GRSchema.xsd
---------
<?xml version="1.0" encoding="UTF-8"?>
<!-- Schema for Grills-->
 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
					 xmlns="http://grillrite.com/grills"
					 targetNamespace="http://grillrite.com/grills">
					 
<xsd:element name="Grills">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="Model" minOccurs="1" maxOccurs="unbounded" type="M_Elements"/>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>
 
 <xsd:complexType name="M_Elements">
	<xsd:sequence>
		<xsd:element name="Name" type="xsd:string"/>
		 <xsd:element name="Price" type="xsd:string"/>
		 <xsd:element name="InStock" type="xsd:positiveInteger"/>
		 <xsd:element name="Parts" type="PartType"/>
	</xsd:sequence>
</xsd:complexType>
 
<xsd:simpleType name="PartNames">
	<xsd:restriction base="xsd:string">
		<xsd:enumeration value="Main Burner"/>
		<xsd:enumeration value="Side Burner"/>
		<xsd:enumeration value="Standard Chassis"/>
		<xsd:enumeration value="Extended Chassis"/>
		<xsd:enumeration value="Controls"/>
		<xsd:enumeration value="Gas Tubing"/>
		<xsd:enumeration value="Igniter"/>
		<xsd:enumeration value="Main Rack"/>
		<xsd:enumeration value="Top Rack"/>
		<xsd:enumeration value="Side Rack"/>
		<xsd:enumeration value="Stand"/>
	</xsd:restriction>
</xsd:simpleType>
 
<xsd:complexType name="PartType">
	<xsd:sequence>
		<xsd:element name="Part"/>
	</xsd:sequence>	
	<xsd:attribute name="Qty" type="xsd:positiveInteger" use="required"/>
</xsd:complexType>
 
<xsd:complexType name="PartsType">
	<xsd:sequence>
		<xsd:element name="PartType" minOccurs="1" maxOccurs="unbounded"/>
	</xsd:sequence>
</xsd:complexType>
 
</xsd:schema>

Open in new window

Avatar of dan_neal
dan_neal
Flag of United States of America image

Not strong with XSDs but wouldn't you need to move the attribute Qty inside the sequence for PartType?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The root of the problem is that the M_Elements type refers to the singular PartType instead of the plural PartsType. Very hard to see that kind of error.