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(非该题的检验 这里只给出相似的过程结果)
如果有错,则会指出相应错误
把答案写下来 下次复习的时候过来看_(:зゝ∠)_