• XML第一次简单入门(Lab分析)


    In this tutorial you will create a well-formed and verified XML file. Consider the XML document below

    <?xml version="1.0"?>
    <!DOCTYPE ancient_wonders [
    <!ELEMENT ancient_wonders (wonder*)>
    <!ELEMENT wonder (name, location, height)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT location (#PCDATA)>
    <!ELEMENT height (#PCDATA)>
    <!ATTLIST height units CDATA #REQUIRED>
    ]>
    <ancient_wonders>
    <wonder>
    <name>Colossus of Rhodes</name>
    <location>Rhodes, Greece</location>
    <height units="feet">107</height>
    </wonder>
    </ancient_wonders>

    1. In the above XML document, add another ancient wonder element for the "Great Pyramid of Giza" located at Giza in Egypt and with the height of 455 feet. Save as “ancient-wonders.xml”

    2. For element of Collossus of Rhodes in this XML document, just below the element, add an empty element <main_image> with attribute filename whose value is “colossus.jpg”. 

    3. Accomodate the DTD of “ancient-wonders.xml” to question 2.

    4. Validate ancient-wonders.xml using xmllint.

    5. Copy the “ancient_wonders” instance at the top (without DTD) to the XML instance document “ancient-wondersxsd.xml”.

    6. Build an xml schema definition for ancient-wonders-xsd.xml and save it as “ancient-wonders.xsd”.

    7. Validate the “ancient-wonders-xsd.xml” against “ancient-wonders.xsd” using xmllint. Submit the three documents via Stream.

    第一,二,三问:

    ancident-wonders.xml

    <?xml version="1.0"?>
    <!DOCTYPE ancient_wonders[
        <!ELEMENT ancient_wonders (wonder*)>
        <!ELEMENT wonder (name, main_image?, location, height)>
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT main_image EMPTY>
        <!ATTLIST main_image filename CDATA #REQUIRED>
        <!ELEMENT location (#PCDATA)>
        <!ELEMENT height (#PCDATA)>
        <!ATTLIST height units CDATA #REQUIRED>
    ]>
    
    <ancient_wonders>
            <wonder>
                    <name>Colossus of Rhodes</name> 
                    <main_image filename="colossus.jpg"/>
                    <location>Rhodes, Greece</location> 
                    <height units="feet">107</height> 
            </wonder>
            
            <wonder>
                    <name>Great Pyramid of Giza</name> 
                    <location>Giza, Egypt</location> 
                    <height units="feet">455</height> 
            </wonder>
    </ancient_wonders>

    第五问:

    <ancient_wonders>
            <wonder>
                    <name>Colossus of Rhodes</name> 
                    <main_image filename="colossus.jpg"/>
                    <location>Rhodes, Greece</location> 
                    <height units="feet">107</height> 
            </wonder>
            <wonder>
                    <name>Great Pyramid of Giza</name> 
                    <location>Giza, Egypt</location> 
                    <height units="feet">455</height> 
            </wonder>
    </ancient_wonders>

    第六问:

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="ancient_wonders">
          <xs:complexType>
            <xs:sequence minOccurs="0">
              <xs:element name="wonder" type="wonder" maxOccurs="10"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        
        <xs:complexType name="wonder">
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="main_image" type="main_image" minOccurs="0"/>
            <xs:element name="location" type="xs:string"/>
            <xs:element name="height" type="height"/> 
          </xs:sequence>
        </xs:complexType>
        
        <xs:complexType name="main_image">
          <xs:attribute name="filename" type="xs:string" use="required"/>
        </xs:complexType>
    
        <xs:complexType name="height">
          <xs:simpleContent>
            <xs:extension base="xs:integer">
              <xs:attribute name="units" type="xs:string" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
    </xs:schema>
            

    然后利用xmllint验证dtd,schema(非该题的检验 这里只给出相似的过程结果)

     

    如果有错,则会指出相应错误

    把答案写下来 下次复习的时候过来看_(:зゝ∠)_

  • 相关阅读:
    IntelliJ Idea 常用快捷键列表
    JSON,字符串,MAP转换
    学习总是无效,是因为你没有稳定的输出系统
    华为离职副总裁徐家骏:透露年薪千万的工作感悟,太震撼了!
    Junit测试Spring应用Dubbo测试框架之-Excel 工具类
    Junit参数化测试Spring应用Dubbo接口
    TestNG参数化测试Spring应用Dubbo接口
    TestNG测试报告美化
    TestNG系列之四: TestNg依赖 dependsOnMethods
    【Java】Java_08 字符型与布尔值
  • 原文地址:https://www.cnblogs.com/northernmashiro/p/9083526.html
Copyright © 2020-2023  润新知