Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

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

0
catonthecouchproductions
Asked:
catonthecouchproductions
1 Solution
 
dan_nealCommented:
Not strong with XSDs but wouldn't you need to move the attribute Qty inside the sequence for PartType?
0
 
Geert BormansCommented:
There are some smaller issues to be solved.
Here is the fixed schema
<?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="PartsType"/>
        </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:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="Qty" type="xsd:positiveInteger" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
     </xsd:complexType>
    
    <xsd:complexType name="PartsType">
        <xsd:sequence>
            <xsd:element name="Part" minOccurs="1" maxOccurs="unbounded" type="PartType" />
        </xsd:sequence>
    </xsd:complexType>
    
</xsd:schema>

Open in new window

0
 
Craig YellickDatabase ArchitectCommented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now