?
Solved

xml and schema problem

Posted on 2009-04-28
6
Medium Priority
?
1,347 Views
Last Modified: 2013-11-18
hi,
i have this xml file and schema file in which i am using xmlspy to produce. the schema is valid and well fromed acording to spy but when i come to apply it to my xml file it comes usp with an error

File C:\Documents and Settings\Administrator\My Documents\XML\Structure.xml is not well-formed.
      More characters are grammatically required
            Reason: one of the following is expected (see below)
                  '<'
                  '<!--'
                  '<![CDATA['
                  '</'
                  '<?'
                  CharData
            Details
                  XML production: Production 'content' not satisfied

why is this? any ideas

thanks in advance
Xml file
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lappy.xslt"?>
<Structure xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com Structure.xsd">
<navigation>
		<menu>
			<id>home</id>
			<title>Home Page</title>
				<menu>
					<id>homeproducts</id>
					<title>Home Products</title>
					<url>homeproducts.html</url>
					<submenu>
						<id>homefurniture</id>
						<title>Home Furniture</title>
						<url>homefurniture.html</url>
					<submenu>
						<id>homeelectrical</id>
						<title>Home Electrical</title>
						<url>homeelectrical.html</url>
					<submenu>
						<id>homeentertainment</id>
						<title>Home Entertainment</title>
						<url>homeentertainment.html</url>
					<submenu>
						<id>hometools</id>
						<title>Home Gym</title>
						<url>homegym.html</url>
				<menu>
					<id>gardenproducts</id>
					<title>Garden Products</title>
					<url>gardenproducts.html</url>
					<submenu>
						<id>gardenfurniture</id>
						<title>Garden Furniture</title>
						<url>gardenfurniture.html</url>
					<submenu>
						<id>gardenelectrical</id>
						<title>Garden Electrical</title>
						<url>gardenelectrical.html</url>
					<submenu>
						<id>gardenentertainment</id>
						<title>Garden Entertainment</title>
						<url>gardenentertainment.html</url>
					<submenu>
						<id>gardentools</id>
						<title>Garden Tools</title>
						<url>gardentools.html</url>
				<menu>
					<id>gymproducts</id>
					<title>Gym Products</title>
					<url>gymproducts.html</url>
					<submenu>
						<id>weights</id>
						<title>Weights</title>
						<url>gymweights.html</url>
					<submenu>
						<id>treadmills</id>
						<title>Treadmills</title>
						<url>gymtreadmills.html</url>
					<submenu>
						<id>exercisebikes</id>
						<title>Exercise Bikes</title>
						<url>gymexercisebikes.html</url>
					<submenu>
						<id>accesories</id>
						<title>Gym accesories</title>
						<url>gymaccesories.html</url>
				<menu>
					<id>computerproducts</id>
					<title>Computer Products</title>
					<url>compproducts.html</url>
					<submenu>
						<id>pcs</id>
						<title>PCs</title>
						<url>comppcs.html</url>
					<submenu>
						<id>laptops</id>
						<title>Laptops</title>
						<url>complaptops.html</url>
					<submenu>
						<id>storage</id>
						<title>computerStorage</title>
						<url>compstorage.html</url>
					<submenu>
						<id>compaccesories</id>
						<title>Comp Accesories</title>
						<url>compaccesories.html</url>		
					</submenu>
					</submenu>
					</submenu>
					</submenu>
					</menu>
					</submenu>
					</submenu>
					</submenu>	
					</submenu>
					</menu>
					</submenu>
					</submenu>	
					</submenu>
					</submenu>
					</menu>
					</submenu>		
				</submenu>
				</submenu>
				</submenu>
				</menu>
			</menu>
	</navigation>
 
xsd file
 
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xsd:element name="navigation">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="menu">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="id" type="xsd:string" />
              <xsd:element name="title" type="xsd:string" />
              <xsd:element name="menu">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="id" type="xsd:string" />
                    <xsd:element name="title" type="xsd:string" />
                    <xsd:element name="url" type="xsd:string" />
                    <xsd:element name="submenu">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="id" type="xsd:string" />
                          <xsd:element name="title" type="xsd:string" />
                          <xsd:element name="url" type="xsd:string" />
                          <xsd:element name="submenu">
                            <xsd:complexType>
                              <xsd:sequence>
                                <xsd:element name="id" type="xsd:string" />
                                <xsd:element name="title" type="xsd:string" />
                                <xsd:element name="url" type="xsd:string" />
                                <xsd:element name="submenu">
                                  <xsd:complexType>
                                    <xsd:sequence>
                                      <xsd:element name="id" type="xsd:string" />
                                      <xsd:element name="title" type="xsd:string" />
                                      <xsd:element name="url" type="xsd:string" />
                                      <xsd:element name="submenu">
                                        <xsd:complexType>
                                          <xsd:sequence>
                                            <xsd:element name="id" type="xsd:string" />
                                            <xsd:element name="title" type="xsd:string" />
                                            <xsd:element name="url" type="xsd:string" />
                                            <xsd:element name="menu">
                                              <xsd:complexType>
                                                <xsd:sequence>
                                                  <xsd:element name="id" type="xsd:string" />
                                                  <xsd:element name="title" type="xsd:string" />
                                                  <xsd:element name="url" type="xsd:string" />
                                                  <xsd:element name="submenu">
                                                    <xsd:complexType>
                                                      <xsd:sequence>
                                                        <xsd:element name="id" type="xsd:string" />
                                                        <xsd:element name="title" type="xsd:string" />
                                                        <xsd:element name="url" type="xsd:string" />
                                                        <xsd:element name="submenu">
                                                          <xsd:complexType>
                                                            <xsd:sequence>
                                                              <xsd:element name="id" type="xsd:string" />
                                                              <xsd:element name="title" type="xsd:string" />
                                                              <xsd:element name="url" type="xsd:string" />
                                                              <xsd:element name="submenu">
                                                                <xsd:complexType>
                                                                  <xsd:sequence>
                                                                    <xsd:element name="id" type="xsd:string" />
                                                                    <xsd:element name="title" type="xsd:string" />
                                                                    <xsd:element name="url" type="xsd:string" />
                                                                    <xsd:element name="submenu">
                                                                      <xsd:complexType>
                                                                        <xsd:sequence>
                                                                          <xsd:element name="id" type="xsd:string" />
                                                                          <xsd:element name="title" type="xsd:string" />
                                                                          <xsd:element name="url" type="xsd:string" />
                                                                          <xsd:element name="menu">
                                                                            <xsd:complexType>
                                                                              <xsd:sequence>
                                                                                <xsd:element name="id" type="xsd:string" />
                                                                                <xsd:element name="title" type="xsd:string" />
                                                                                <xsd:element name="url" type="xsd:string" />
                                                                                <xsd:element name="submenu">
                                                                                  <xsd:complexType>
                                                                                    <xsd:sequence>
                                                                                      <xsd:element name="id" type="xsd:string" />
                                                                                      <xsd:element name="title" type="xsd:string" />
                                                                                      <xsd:element name="url" type="xsd:string" />
                                                                                      <xsd:element name="submenu">
                                                                                        <xsd:complexType>
                                                                                          <xsd:sequence>
                                                                                            <xsd:element name="id" type="xsd:string" />
                                                                                            <xsd:element name="title" type="xsd:string" />
                                                                                            <xsd:element name="url" type="xsd:string" />
                                                                                            <xsd:element name="submenu">
                                                                                              <xsd:complexType>
                                                                                                <xsd:sequence>
                                                                                                  <xsd:element name="id" type="xsd:string" />
                                                                                                  <xsd:element name="title" type="xsd:string" />
                                                                                                  <xsd:element name="url" type="xsd:string" />
                                                                                                  <xsd:element name="submenu">
                                                                                                    <xsd:complexType>
                                                                                                      <xsd:sequence>
                                                                                                        <xsd:element name="id" type="xsd:string" />
                                                                                                        <xsd:element name="title" type="xsd:string" />
                                                                                                        <xsd:element name="url" type="xsd:string" />
                                                                                                        <xsd:element name="menu">
                                                                                                          <xsd:complexType>
                                                                                                            <xsd:sequence>
                                                                                                              <xsd:element name="id" type="xsd:string" />
                                                                                                              <xsd:element name="title" type="xsd:string" />
                                                                                                              <xsd:element name="url" type="xsd:string" />
                                                                                                              <xsd:element name="submenu">
                                                                                                                <xsd:complexType>
                                                                                                                  <xsd:sequence>
                                                                                                                    <xsd:element name="id" type="xsd:string" />
                                                                                                                    <xsd:element name="title" type="xsd:string" />
                                                                                                                    <xsd:element name="url" type="xsd:string" />
                                                                                                                    <xsd:element name="submenu">
                                                                                                                      <xsd:complexType>
                                                                                                                        <xsd:sequence>
                                                                                                                          <xsd:element name="id" type="xsd:string" />
                                                                                                                          <xsd:element name="title" type="xsd:string" />
                                                                                                                          <xsd:element name="url" type="xsd:string" />
                                                                                                                          <xsd:element name="submenu">
                                                                                                                            <xsd:complexType>
                                                                                                                              <xsd:sequence>
                                                                                                                                <xsd:element name="id" type="xsd:string" />
                                                                                                                                <xsd:element name="title" type="xsd:string" />
                                                                                                                                <xsd:element name="url" type="xsd:string" />
                                                                                                                                <xsd:element name="submenu">
                                                                                                                                  <xsd:complexType>
                                                                                                                                    <xsd:sequence>
                                                                                                                                      <xsd:element name="id" type="xsd:string" />
                                                                                                                                      <xsd:element name="title" type="xsd:string" />
                                                                                                                                      <xsd:element name="url" type="xsd:string" />
                                                                                                                                    </xsd:sequence>
                                                                                                                                  </xsd:complexType>
                                                                                                                                </xsd:element>
                                                                                                                              </xsd:sequence>
                                                                                                                            </xsd:complexType>
                                                                                                                          </xsd:element>
                                                                                                                        </xsd:sequence>
                                                                                                                      </xsd:complexType>
                                                                                                                    </xsd:element>
                                                                                                                  </xsd:sequence>
                                                                                                                </xsd:complexType>
                                                                                                              </xsd:element>
                                                                                                            </xsd:sequence>
                                                                                                          </xsd:complexType>
                                                                                                        </xsd:element>
                                                                                                      </xsd:sequence>
                                                                                                    </xsd:complexType>
                                                                                                  </xsd:element>
                                                                                                </xsd:sequence>
                                                                                              </xsd:complexType>
                                                                                            </xsd:element>
                                                                                          </xsd:sequence>
                                                                                        </xsd:complexType>
                                                                                      </xsd:element>
                                                                                    </xsd:sequence>
                                                                                  </xsd:complexType>
                                                                                </xsd:element>
                                                                              </xsd:sequence>
                                                                            </xsd:complexType>
                                                                          </xsd:element>
                                                                        </xsd:sequence>
                                                                      </xsd:complexType>
                                                                    </xsd:element>
                                                                  </xsd:sequence>
                                                                </xsd:complexType>
                                                              </xsd:element>
                                                            </xsd:sequence>
                                                          </xsd:complexType>
                                                        </xsd:element>
                                                      </xsd:sequence>
                                                    </xsd:complexType>
                                                  </xsd:element>
                                                </xsd:sequence>
                                              </xsd:complexType>
                                            </xsd:element>
                                          </xsd:sequence>
                                        </xsd:complexType>
                                      </xsd:element>
                                    </xsd:sequence>
                                  </xsd:complexType>
                                </xsd:element>
                              </xsd:sequence>
                            </xsd:complexType>
                          </xsd:element>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Open in new window

0
Comment
Question by:kipl20
  • 4
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24248559
well, your schema does no specify a "structure" element as the root
and you don't have a namespace

so you should reference your schema like this


<navigation 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="Navigation.xsd">
        <menu>

Open in new window

0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 1500 total points
ID: 24248569
Unless you realy want to control the document structure as you do,
by literally mimicing the entire pattern,
there are smarter ways to create a nested schema

I by the way still think that your XML has a logical error
(as I said before)
Submenu should not have menu children, they should be siblings

I have created a schema that allows menu inside submenu... but in my mind that is a logical error
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified">
 
    <xsd:element name="menu">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="id" type="xsd:string" />
                <xsd:element name="title" type="xsd:string" />
                <xsd:element name="url" minOccurs="0" type="xsd:anyURI"></xsd:element>
                <xsd:choice minOccurs="0" maxOccurs="1">
                    <xsd:element ref="menu"  />
                    <xsd:element ref="submenu"  />
                </xsd:choice>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
 
    <xsd:element name="submenu">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="id" type="xsd:string" />
                <xsd:element name="title" type="xsd:string" />
                <xsd:element name="url" minOccurs="0" type="xsd:anyURI"></xsd:element>
                <xsd:choice minOccurs="0" maxOccurs="1">
                    <xsd:element ref="menu"  />
                    <xsd:element ref="submenu"  />
                </xsd:choice>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    
    <xsd:element name="navigation">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="menu"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

Open in new window

0
 

Author Comment

by:kipl20
ID: 24249032
thanks gertone, i saw what the problem was i was referencing the element navigation twice like you said. your schema works perfect. could you explain a little on what it is doing?
like this part

 <xsd:choice minOccurs="0" maxOccurs="1">
                    <xsd:element ref="menu"  />
                    <xsd:element ref="submenu"  />
                </xsd:choice>

and this

 <xsd:element name="navigation">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="menu"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

thanks alot for your time and help
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kipl20
ID: 24249891
hi, think i have sorted the structure so its more logical?

i now use the xml and the schema below, does this look ok?
xml file
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lappy.xslt"?>
<navigation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Structure.xsd">
	<menu>
		<id>homeproducts</id>
		<title>Home Products</title>
		<url>homeproducts.html</url>
		<submenu>
			<id>homefurniture</id>
			<title>Home Furniture</title>
			<url>homefurniture.html</url>
		</submenu>
		<submenu>
			<id>homeelectrical</id>
			<title>Home Electrical</title>
			<url>homeelectrical.html</url>
		</submenu>
		<submenu>
			<id>homeentertainment</id>
			<title>Home Entertainment</title>
			<url>homeentertainment.html</url>
		</submenu>
		<submenu>
			<id>hometools</id>
			<title>Home Gym</title>
			<url>homegym.html</url>
		</submenu>
	</menu>
	<menu>
		<id>gardenproducts</id>
		<title>Garden Products</title>
		<url>gardenproducts.html</url>
		<submenu>
			<id>gardenfurniture</id>
			<title>Garden Furniture</title>
			<url>gardenfurniture.html</url>
		</submenu>
		<submenu>
			<id>gardenelectrical</id>
			<title>Garden Electrical</title>
			<url>gardenelectrical.html</url>
		</submenu>
		<submenu>
			<id>gardenentertainment</id>
			<title>Garden Entertainment</title>
			<url>gardenentertainment.html</url>
		</submenu>
		<submenu>
			<id>gardentools</id>
			<title>Garden Tools</title>
			<url>gardentools.html</url>
		</submenu>
	</menu>
	<menu>
		<id>gymproducts</id>
		<title>Gym Products</title>
		<url>gymproducts.html</url>
		<submenu>
			<id>weights</id>
			<title>Weights</title>
			<url>gymweights.html</url>
		</submenu>
		<submenu>
			<id>treadmills</id>
			<title>Treadmills</title>
			<url>gymtreadmills.html</url>
		</submenu>
		<submenu>
			<id>exercisebikes</id>
			<title>Exercise Bikes</title>
			<url>gymexercisebikes.html</url>
		</submenu>
		<submenu>
			<id>accesories</id>
			<title>Gym accesories</title>
			<url>gymaccesories.html</url>
		</submenu>
	</menu>
	<menu>
		<id>computerproducts</id>
		<title>Computer Products</title>
		<url>compproducts.html</url>
		<submenu>
			<id>pcs</id>
			<title>PCs</title>
			<url>comppcs.html</url>
		</submenu>
		<submenu>
			<id>laptops</id>
			<title>Laptops</title>
			<url>complaptops.html</url>
		</submenu>
		<submenu>
			<id>storage</id>
			<title>computerStorage</title>
			<url>compstorage.html</url>
		</submenu>
		<submenu>
			<id>compaccesories</id>
			<title>Comp Accesories</title>
			<url>compaccesories.html</url>
		</submenu>
	</menu>
</navigation>
 
schema
 
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
	<xsd:element name="navigation">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="menu" maxOccurs="unbounded">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="id" type="xsd:string"/>
							<xsd:element name="title" type="xsd:string"/>
							<xsd:element name="url" type="xsd:string"/>
							<xsd:element name="submenu" maxOccurs="unbounded">
								<xsd:complexType>
									<xsd:sequence>
										<xsd:element name="id" type="xsd:string"/>
										<xsd:element name="title" type="xsd:string"/>
										<xsd:element name="url" type="xsd:string"/>
									</xsd:sequence>
								</xsd:complexType>
							</xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24250367
I have been in a meeting for a while

<xsd:choice minOccurs="0" maxOccurs="1">
                    <xsd:element ref="menu"  />
                    <xsd:element ref="submenu"  />
                </xsd:choice>

just means that at the end of the sequence for menu there can be a menu or submenu (or nothing)
the ref attribute makes a reference to a globally declared element (itself in this case, that is how you build the indefinite nesting)

<xsd:element name="navigation">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="menu"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

says that the top level element navigation has one menu element, as defined later on
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24250382
The new XML makes more sense, done well.
You should have used the schema as I showed you, with references to globaly declared elements,
but if this new schema of yours, works for you, leave it that way
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question