xml复合文档错误

时间:2017-03-15 00:53:34

标签: xml xsd

在我开始添加命名空间之前,每件事情都运行正常,并尝试使用此代码帮助制作复合文档 这是第一个文件 它是一个复合xml文档

    <?xml version="1.0" encoding="UTF-8" ?>

    <pr:city  name="paris"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:pr="http://example.com/paris/city/ns"
    xsi:SchemaLocation=" http://example.com/paris/city/ns paris.xsd">

    <!--
   New Perspectives on XML
   Mid-Term project
   Paris  Travel Guide 
   Author: Amanpreet kaur kohli
   Date:  03/02/2017

   Filename:         paris.xml

-->



    <!--
about us describe history, social, population of the paris
-->
       <heading>PARIS</heading>
       <title>About Us</title>
       <description>
        <![CDATA[
        Paris is the capital and most populous city of France. It has an area of        105 square kilometres (41 square miles) and a population in 2013 of 2,229,621 
within its administrative limits.The city is both a commune and department, and forms the centre and headquarters of the Île-de-France, or Paris Region, 
which has an area of 12,012 square kilometres (4,638 square miles) and a population in 2014 of 12,005,077, comprising 18.2 percent of the population of France.

    The agglomeration has grown well beyond the city's administrative limits. 
The Paris unité urbaine is a measure of continuous urban area for statistical purposes, 
including both the commune and its suburbs, and has a population of 10,601,122 (Jan. 2013 census) 
which makes it the largest in the European Union.

Paris received 22.2 million visitors, making it one of the world's top tourist destinations. 
and is also known for its fashion, particularly the twice-yearly Paris Fashion Week, and for its 
haute cuisine, and three-star restaurants. Most of France's major universities and grandes écoles are located in Paris, as are France's major newspapers, 
including Le Monde, Le Figaro, and Libération.
]]>
       </description>
       <history>
        <![CDATA[
Paris was founded in the 3rd century BC by a Celtic people called the Parisii, 
who gave the city its name. By the 12th century, it was the largest city in the western world, 
a prosperous trading centre, and the home of the University of Paris, one of the oldest universities in history. 
By the 17th century Paris was one of Europe's major centres of finance, commerce, fashion, science, and the arts, and it retains that position still today.
]]>
       </history>
    <!--
famous place show the brief description of the most visted places in paris 
name and type are the attribute of place and attraction
attribute type is a enumeration type
attribute name is a string type 
-->
       <places>
           <place location="Louvre">
             <attraction type="museum"/>
            <dbuilt>1546</dbuilt>
        </place>
        <place location="Musee National d' Art Moderene">
            <attraction type="museum"/>
            <dbuilt>1937</dbuilt>
        </place>
        <plac`enter code here`e location="Notre Dame Cathedral">
            <attraction type="monument"/>
            <dbuilt>1345</dbuilt>
        </place>
        <place location="Saint Chapelle">
            <attraction type="monument"/>
            <dbuilt>1248</dbuilt>
        </place>
        <place location="Eiffel Tower">
            <attraction type="landmark"/>
            <dbuilt>1889</dbuilt>
        </place>
        <place location="Basilica of Sacred Heart of Paris">
            <attraction type="monument"/>
            <dbuilt>1914</dbuilt>
        </place>
    </places>
    <events>
        <event category="exhibition">
            <name>Joann Sfar- Salvador Dali, one Second Before Awakening </name>
            <location>11 rue Poulbot - 75018 Paris</location>
            <price>11.00 euro</price>
        </event>
        <event category="exhibition">
            <name>Icons of Mordern Art, the Shchukin Collection</name>
            <location>8 avenue du Mahatma Gandhi, Paris</location>
            <price>16.00 euro</price>
        </event>
        <event category="exhibition">
            <name>Vermeer and the Masters of Genre Painting </name>
            <location>Musée du Louvre, Paris</location>
            <price>15.00 euro</price>
        </event>
        <event category="shows">
            <name>Priscilla , Oueen of the Desert</name>
            <location>16 rue de Clichy, Paris</location>
            <price>25.00 to 70.00 euro</price>
        </event>
        <event category="cabaret">
            <name>The Moulin Rouge</name>
            <location>82 Boulevard de Clichy Paris 18th </location>
            <price>112.00 euro</price>
        </event>
    </events>

    <ac:activites xmlns:ac="http://www.example.com/paris/activites/ns"
                xsi:schemaLocation="http://www.example.com/paris/activites/ns activities.xsd">
<!--
   New Perspectives on XML
   Mid-Term project
   Paris  Travel Guide 
   Author: Amanpreet kaur kohli
   Date:  03/02/2017

   Filename:         activites.xml

-->

<heading> Things To Do </heading>
<title> activites</title>
<activity type="tour">
<name> Paris Illuminations Tour</name>
<description>After nightfall, the streets of Paris take on a magical aspect: Paris lights up. Discover the magic of Paris by night!
The best way to enjoy many of the beautifully-illuminated landmarks is on a bus tour.
Hop aboard an air-conditioned bus with a panoramic roof for a tour of the City of Light. Relive the history of Paris while discovering the illuminations of the capital.
Your tour will take you to iconic places such as Place Vendôme, the Île de la Cité and Notre-Dame Cathedral, Place de la Concorde, the Avenue des Champs Elysées, the Eiffel Tower, the Palais Garnier Opera House …
At the end of this 1hr45 tour, you have the choice of being dropped off at one of 3 points in the centre of Paris: Opéra, Pyramides or Châtelet.
</description>
<price> 30 euro</price>
<language> English , Spanish, Italian, Portuguese, Russian , French</language>
<duration> 1 hour and 45 mintues</duration>
<timing> everday at 10pm</timing>
</activity>

<activity type="dinner tour">
<name>Dinner-Cruise La Marina, Eiffel Tower And Moulin Rouge</name>
<description>You will begin the evening aboard the ‘Marina de Paris’ restaurant boat. 
you will glide through the City of Light admiring the Seine riverbanks whilst enjoying your meal. 
You will pass under the most emblematic bridges in the capital such as the Alexandre III bridge and alongside the most famous monuments: the Eiffel Tower, 
Notre Dame, the Orsay Museum, the Grand Palais. 

After dinner, your boat will stop at the foot of the Eiffel Tower to give you direct access to it. 
Your fast-track ticket will enable you to go straight up to the 2nd floor without having to queue. 
Enjoy the magnificent views at your leisure.

At the foot of the Eiffel Tower, a luxury bus will take you to the famous Le Moulin Rouge cabaret. 
Known throughout the world for its famous cancan, the Moulin Rouge still reflects the spirit of the belle époque. 
You will see a performance of the revue ‘Féerie’ featuring 80 artistes and sequined and feathered costumes that will transport you into a magical world. 
You will also be served half a bottle of champagne per person.

At the end of this enchanting evening, you will be taken back to the area in which your hotel is situated in Paris.
</description>
<price> 255 Euro</price>
<language> English, French, Italian </language>
<duration> 7 hours </duration>
<timing> every night 6pm </timing>
</activity>

<activity type="show">
<name> HOW TO BECOME PARISIAN IN ONE HOUR </name>
<description>You love Paris but you think that Parisians are rude? You're right, they are!
You are too nice and you want to become arrogant?
Don't wait and come to THE training approved by more than 500 000 spectators!
</description>
<price> 24  Euro </price>
<language> English</language>
<duration> 1 hour and 10  mintues </duration>
<timing> Every Firday and Saturday at 7pm </timing>
</activity>

<activity type="dinner">
<name>Dinner at the Restaurant 58 Tour Eiffel</name>
<description>Enjoy the thrill of dining on the 1st floor of the Eiffel Tower, 
in a minimalist setting. With its transparent facades, the 58 Tour Eiffel offers you an 
amazing view of the City of Light. Relive the time of the Universal Exhibition and savour 
an exceptional meal at this fashionable Parisian restaurant.
</description>
<price> 85 Euro </price>
<language> english , french, Italian</language>
<duration> 2 to 3 hours</duration>
<timing> 6:30pm and 9:00pm </timing>
</activity>
</ac:activites>
</pr:city>

接下来是xsd文件

<?xml version="1.0" encoding="utf-8"  ?>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://example.com/paris/city/ns"
    targetNamespace="http://example.com/paris/city/ns"
    xmlns:ac="http://www.example.com/paris/activites/ns">

    <xsi:import namespace="http://www.example.com/paris/activites/ns"
        schemaLocation="http://www.example.com/paris/activites activities.xsd" />

     <xsi:element name="heading" type="xs:string"/>
    <xsi:element name="title" type="xs:string"/>
    <xsi:element name="description" type="xs:string"/>
    <xsi:element name="history" type="xs:string"/>
    <xsi:element name="dbuilt" type="xs:integer"/>
    <xsi:element name="name" type="xs:string"/>
    <xsi:element name="location" type="xs:string"/>
    <xsi:element name="price" type="xs:string"/>


    <xsi:element name="city">
        <xsi:complexType>
            <xsi:sequence>
                <xsi:element ref="heading"/>
                <xsi:element ref="title"/>
                <xsi:element ref="description"/>
                <xsi:element ref="history"/>
                <xsi:element ref="places"/>
                <xsi:element ref="events"/>
            </xsi:sequence>
            <xsi:attribute ref="xsi:noNamespaceSchemaLocation" use="required"/>
            <xsi:attribute name="name" use="required" type="xs:string"/>
        </xsi:complexType>
    </xsi:element>

    <xsi:element name="places">
        <xsi:complexType>
            <xsi:sequence>
                <xsi:element maxOccurs="unbounded" ref="place"/>
            </xsi:sequence>
        </xsi:complexType>
    </xsi:element>

    <xsi:element name="place">
        <xsi:complexType>
            <xsi:sequence>
                <xsi:element ref="attraction"/>
                <xsi:element ref="dbuilt"/>
            </xsi:sequence>
            <xsi:attribute name="location" use="required"/>
        </xsi:complexType>
    </xsi:element>

    <xsi:element name="attraction">
        <xsi:complexType>
            <xsi:attribute name="type" use="required" type="xs:string"/>
        </xsi:complexType>
    </xsi:element>


    <xsi:element name="events">
        <xsi:complexType>
            <xsi:sequence>
                <xsi:element maxOccurs="unbounded" ref="event"/>
            </xsi:sequence>
        </xsi:complexType>
    </xsi:element>

    <xsi:element name="event">
        <xsi:complexType>
            <xsi:sequence>
                <xsi:element ref="name"/>
                <xsi:element ref="location"/>
                <xsi:element ref="price"/>
            </xsi:sequence>
            <xsi:attribute name="category" use="required" type="xs:string"/>
        </xsi:complexType>
    </xsi:element>
    <xsi:element ref="ac:activites"/>

</xsi:schema>

它向我显示了一些错误,如下所示

Description: Failed to read schema document 'http://www.example.com/paris/activites activities.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. schema_reference.4
File: paris.xsd 8:82
Processor: Xerces 2

Description: Invalid attribute value for 'type' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'xs:string' as a QName: the prefix 'xs' is not declared. s4s-att-invalid-value
File: paris.xsd 10:52
Processor: Xerces 2

Description: Invalid attribute value for 'type' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'xs:string' as a QName: the prefix 'xs' is not declared. s4s-att-invalid-value
File: paris.xsd 11:49
Processor: Xerces 2


Description: Cannot resolve the name 'xsi:noNamespaceSchemaLocation' to a(n) 'attribute declaration' component. src-resolve
File: paris.xsd 30:80
Processor: Xerces 2

Description: Cannot resolve the name 'xsi:noNamespaceSchemaLocation' to a(n) 'attribute declaration' component. src-resolve
File: paris.xsd 30:80
Processor: Xerces 2


Description: Attribute 'ref' cannot appear in element 'element'. s4s-att-not-allowed
File: paris.xsd 78:38
Processor: Xerces 2

1 个答案:

答案 0 :(得分:0)

你显然会从一些basic reading on namespaces in XSD中受益。您需要解决的众多问题包括:

  • 命名空间前缀可以是任意的,但不要违反惯例 使用xsi,通常用于 http://www.w3.org/2001/XMLSchema-instance,用于XSD名称空间 字首;请改用xsxsd
  • xs:import/@schemaLocation是XSD的URL,而不是namespace-URI 对
  • 请勿尝试明确定义noNamespaceSchemaLocation 你的XSD。看到 How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

有关工作示例,请参阅XML XSD namespace issues(了解basics后)。