By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Importing schemas: Cannot resolve the name to a(n) 'element declaration

P: 4
Hi all,

I'm fairly new to XML, however already I have studied myself stupid without being able to solve this problem. Basically, I have an XML file/Schema about a CD catalog that I've created that I want to combine with an XML/Schema that a friend has created. Both XML files/Schema validate individually.

Now comes the tricky part, combining them. I've created a new XML file and schema, called catalog.xml and catalog.xsd. Into the catalog.xml file has gone all the XML from both files, using namespaces to seperate each of them (the overall catalog, the cd catalog and the dvd catalog). Because this new file is a combination of two existing files, I want to simply reference the schemas for each, minimising code reproduction. Therefore, my schema for catalog looks like this:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <xs:schema targetNamespace="http://www.carlpaynephotography.com/catalog"
  3.   xmlns:cat="http://www.carlpaynephotography.com/catalog" 
  4.   xmlns:xml="http://www.w3.org/XML/1998/namespace" 
  5.   xmlns:cd="http://www.carlpaynephotography.com/cdcatalog"
  6.   xmlns:dvd="http://www.carlpaynephotography.com/dvdcatalog"
  7.   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  8.   elementFormDefault="qualified"
  9.   attributeFormDefault="unqualified">
  10.   <xs:import namespace="http://www.carlpaynephotography.com/cdcatalog"
  11.   schemaLocation="cdcatalog.xsd"/>
  12.   <xs:import namespace="http://www.carlpaynephotography.com/dvdcatalog"
  13.   schemaLocation="filmstore.xsd"/>
  14.  
  15.   <xs:element name="catalog" type="cat:catType" />
  16.   <xs:complexType name="catType">
  17.       <xs:sequence>
  18.         <xs:element ref="cd:cdcatalog"  maxOccurs="1"/>
  19.         <xs:element ref="dvd:film_store" maxOccurs="1"/>
  20.       </xs:sequence>
  21.     </xs:complexType>
  22. </xs:schema>
  23.  
Essentially, I am trying to say that this new overall catalog contains an instance of cdcatalog and an instance of film_store. However, using the decisionsoft online validator, I get the following problems:

Validation 25, 56 src-resolve: Cannot resolve the name 'cd:cdcatalog' to a(n) 'element declaration' component.
Validation 27, 57 src-resolve: Cannot resolve the name 'dvd:film_store' to a(n) 'element declaration' component.
Validation 7, 68 cvc-complex-type.2.4.d: Invalid content was found starting with element 'cdcatalog'. No child element is expected at this point.

Any ideas what I can do to fix all of this? I feel like I am so close to making everything work. The rest of my code is below:

catalog.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <?xml-stylesheet type="text/xsl" href="catalog.xslt"?>
  3.  
  4. <catalog xmlns="http://www.carlpaynephotography.com/catalog">
  5.   <cdcatalog xmlns="http://www.carlpaynephotography.com/cdcatalog">
  6.         <album>
  7.             <title>Are You Experienced</title>
  8.             <artist>Jimi Hendrix</artist>
  9.             <country>UK</country>
  10.             <release>1997-04-28</release>
  11.             <label>MCA</label>
  12.             <genre>Blues Rock</genre>
  13.             <price>9.99</price>
  14.             <tracks>
  15.                 <track>
  16.                     <number>1</number>
  17.                     <title>Foxy Lady</title>
  18.                 </track>
  19.                 <track>
  20.                     <number>2</number>
  21.                     <title>Manic Depression</title>
  22.                 </track>
  23.                 <track>
  24.                     <number>3</number>
  25.                     <title>Red House</title>
  26.                 </track>
  27.                 <track>
  28.                     <number>4</number>
  29.                     <title>Can You See Me</title>
  30.                 </track>
  31.             </tracks>
  32.             </tracks>
  33.         </album>
  34. </cdcatalog>
  35.     <dvdcatalog xmlns="http://www.carlpaynephotography.com/dvdcatalog">
  36.         <dvd>
  37.             <title>A Beautiful Mind</title>
  38.             <director>Ron Howard</director>
  39.             <run_time>135 mins</run_time>
  40.             <cert>12</cert>
  41.             <studio>Dreamworks</studio>
  42.             <year>2001</year>
  43.             <rent_info>
  44.                 <rent_cost>2.50</rent_cost>
  45.                 <copies>2</copies>
  46.                 <available>Yes</available>
  47.             </rent_info>
  48.         </dvd>
  49. </dvdcatalog>
  50. </catalog>
  51.  


I know this is a LOT to read through but if anyone could offer any suggestions then please do!

Many thanks guys,

Carl
Apr 26 '07 #1
Share this Question
Share on Google+
5 Replies


P: 4
The XML for cdcatalog.xml and film_store.xml is identical to the above, the schemas for each are:

cdcatalog.xsd
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <xs:schema targetNamespace="http://www.carlpaynephotography.com/cdcatalog" 
  3.   xmlns:xml="http://www.w3.org/XML/1998/namespace" 
  4.   xmlns:cd="http://www.carlpaynephotography.com/cdcatalog" 
  5.   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  6.   elementFormDefault="qualified"
  7.   attributeFormDefault="qualified">
  8.  
  9.   <xs:element name="title" type="xs:string"/>
  10.   <xs:element name="artist" type="xs:string"/>
  11.   <xs:element name="country" type="xs:string"/>
  12.   <xs:element name="release">
  13.     <xs:simpleType>
  14.       <xs:restriction base="xs:date">
  15.         <xs:minInclusive value="1900-01-01"/>
  16.       </xs:restriction>
  17.     </xs:simpleType>
  18.   </xs:element>
  19.   <xs:element name="label" type="xs:string"/>
  20.   <xs:element name="genre" type="xs:string"/>
  21.   <xs:element name="price">
  22.     <xs:simpleType>
  23.       <xs:restriction base="xs:decimal">
  24.         <xs:maxInclusive value="99.99"/>
  25.         <xs:fractionDigits value="2" />
  26.       </xs:restriction>
  27.     </xs:simpleType>
  28.   </xs:element>
  29.   <xs:element name="number" type="xs:positiveInteger"/>
  30.  
  31.   <xs:element name="track">
  32.     <xs:complexType>
  33.       <xs:sequence>
  34.         <xs:element ref="cd:number"/>
  35.         <xs:element ref="cd:title"/>
  36.         <xs:element ref="cd:artist" minOccurs="0"/>
  37.       </xs:sequence>
  38.     </xs:complexType>
  39.   </xs:element>
  40.  
  41.   <xs:element name="tracks">
  42.     <xs:complexType>
  43.       <xs:sequence>
  44.         <xs:element ref="cd:track" maxOccurs="unbounded"/>
  45.       </xs:sequence>
  46.     </xs:complexType>
  47.   </xs:element>
  48.  
  49.   <xs:element name="album">
  50.     <xs:complexType>
  51.       <xs:sequence>
  52.         <xs:element ref="cd:title"/>
  53.         <xs:element ref="cd:artist"/>
  54.         <xs:element ref="cd:country"/>
  55.         <xs:element ref="cd:release"/>
  56.         <xs:element ref="cd:label"/>
  57.         <xs:element ref="cd:genre"/>
  58.         <xs:element ref="cd:price"/>
  59.         <xs:element ref="cd:tracks"/>
  60.       </xs:sequence>
  61.     </xs:complexType>
  62.   </xs:element>
  63.  
  64.   <xs:element name="cdcatalog" type="cd:cdType" />
  65.   <xs:complexType name="cdType">
  66.       <xs:sequence>
  67.         <xs:element ref="cd:album" maxOccurs="unbounded"/>
  68.       </xs:sequence>
  69.     </xs:complexType>
  70. </xs:schema>
  71.  
Apr 26 '07 #2

P: 4
filmstore.xsd
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <xs:schema targetNamespace="http://www.carlpaynephotography.com/dvdcatalog" 
  3.   xmlns:xml="http://www.w3.org/XML/1998/namespace" 
  4.   xmlns:dvd="http://www.carlpaynephotography.com/dvdcatalog" 
  5.   xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  6.   elementFormDefault="qualified"
  7.   attributeFormDefault="qualified">
  8.  
  9. <!-- simple element definitions -->
  10. <xs:element name="title" type="xs:string" /> 
  11. <xs:element name="director" type="xs:string" /> 
  12. <xs:element name="run_time" type="dvd:run_time" /> 
  13. <xs:element name="cert" type="dvd:cert_type" /> 
  14. <xs:element name="studio" type="xs:string" /> 
  15. <xs:element name="year" type="dvd:year" /> 
  16. <xs:element name="rent_cost" type="dvd:rent_cost" />
  17. <xs:element name="copies" type="xs:positiveInteger" /> 
  18. <xs:element name="available" type="dvd:available" /> 
  19.  
  20. <xs:simpleType name="run_time">
  21.     <xs:restriction base="xs:string">
  22.         <xs:pattern value="\d+(\s)?(mins)" />
  23.     </xs:restriction>
  24. </xs:simpleType>
  25.  
  26. <xs:simpleType name="cert_type">
  27.     <xs:restriction base="xs:string">
  28.         <xs:enumeration value="Uc" />
  29.         <xs:enumeration value="U" />
  30.         <xs:enumeration value="PG" />
  31.         <xs:enumeration value="12A" />
  32.         <xs:enumeration value="12" />
  33.         <xs:enumeration value="15" />
  34.         <xs:enumeration value="18" />
  35.         <xs:enumeration value="18r" />
  36.     </xs:restriction>
  37. </xs:simpleType>
  38.  
  39. <xs:simpleType name="year">
  40.     <xs:restriction base="xs:integer">
  41.         <xs:pattern value="\d{4}" />
  42.     </xs:restriction>
  43. </xs:simpleType>
  44.  
  45. <xs:simpleType name="rent_cost">
  46.     <!-- based on type integer -->
  47.     <xs:restriction base="xs:string">
  48.         <xs:pattern value="\d+.\d{2}" />
  49.     </xs:restriction>
  50. </xs:simpleType>
  51.  
  52. <xs:simpleType name="available">
  53.     <!-- based on type string -->
  54.     <xs:restriction base="xs:string">
  55.         <xs:enumeration value="No" />
  56.         <xs:enumeration value="no" />
  57.         <xs:enumeration value="Yes" />
  58.         <xs:enumeration value="yes" />
  59.     </xs:restriction>
  60. </xs:simpleType>
  61.  
  62. <xs:element name="rent_info">
  63.     <xs:complexType>
  64.         <xs:sequence>
  65.             <xs:element ref="dvd:rent_cost" /> 
  66.             <xs:element ref="dvd:copies" /> 
  67.             <xs:element ref="dvd:available" /> 
  68.         </xs:sequence>
  69.     </xs:complexType>
  70. </xs:element>
  71.  
  72. <xs:element name="dvd">
  73.     <xs:complexType>
  74.         <xs:sequence>
  75.             <xs:element ref="dvd:title" />
  76.             <xs:element ref="dvd:director" /> 
  77.             <xs:element ref="dvd:run_time" /> 
  78.             <xs:element ref="dvd:cert" /> 
  79.             <xs:element ref="dvd:studio" /> 
  80.             <xs:element ref="dvd:year" /> 
  81.             <xs:element ref="dvd:rent_info" />
  82.         </xs:sequence>
  83.     </xs:complexType>
  84. </xs:element>
  85.  
  86.   <xs:element name="film_store" type="dvd:dvdType" />
  87.   <xs:complexType name="dvdType">
  88.         <xs:sequence>
  89.             <xs:element ref="dvd:dvd" maxOccurs="unbounded" />
  90.         </xs:sequence>
  91.     </xs:complexType>
  92. </xs:schema>
  93.  
Apr 26 '07 #3

dorinbogdan
Expert 100+
P: 839
Welcome to TheScripts TSDN....

The code looks fine on a short overview (excepting that the XML file contains twice the </tracks> element, so one should be removed).

The Decision Soft Validator seems to load just one XSD schema (provided as input, catalog.xsd), and it simply doesn't load the other 2 (cdcatalog.xsd and filmstore.xsd).
Apr 27 '07 #4

P: 4
Hi!

Thanks a lot for the reply, I was beginning to think I was going a bit nuts. The double </tracks> tag is just from me deleting out comments to make my post here shorter and leaving that by mistake, in the actual code it only exists once. Glad to hear that it's not my code which is at fault. Are there any better validation tools out there (either software or online) which do allow multiple schemas?

Nevertheless, thanks for the help, it's a big relief!

Carl
Apr 28 '07 #5

dorinbogdan
Expert 100+
P: 839
I didn't use it, but it's free and seems helpful: AltovaXml.
Apr 30 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.