XML编程与应用教程第二版上机答案

时间:2021-10-12 08:36:57 来源:网友投稿

  上机题 1、 <?xml version="1.0"

 encoding="gb2312"?> <book>

  <title>XML 指南</title>

  <chapter>XML 入门简介

  <para>什么是 HTML</para>

  <para>什么是 XML</para>

  </chapter>

  <chapter>XML 语法

  <para>XML 元素必须有结束标签</para>

  <para>XML 元素必须正确的嵌套</para>

  </chapter> </book> 2、 <?xml version="1.0"

 encoding="gb2312"?> <employees> <employee> <id>1</id> <name>张三</name> <age>32</age> <sex>男</sex> <address>上海</address> </employee>

 <employee> <id>2</id> <name>李四</name> <age>22</age> <sex>男</sex> <address>北京</address> </employee> </employees> 3、 <?xml version="1.0"

 encoding="gb2312"?> <students> <student> <number>1</number> <name>tom</name> <score>100</score> </student> <student> <number>2</number> <name>mary</name> <score>98</score> </student> </students> 第三章 上机题 1、 <?xml version="1.0" encoding="GB2312"?>

  <!ELEMENT 学生名册(学生+)> <!ELEMENT 学生(姓名,性别, 年龄)> <!ELEMENT 姓名(#PCDATA)>

 <!ELEMENT 性别(#PCDATA)> <!ELEMENT 年龄(#PCDATA)>

 <!ATTLIST 学生 学号 ID

 #REQUIRED>

  2、 <?xml version="1.0" encoding="UTF-8"?> <NEWSPAPER> <ARTICLE

 AUTHOR=”&NEWSPAPER;” EDITOR=”&PUBLISHER;” DATE=”2009-6-1”

 EDITION =”&COPYRIGHT;”> <HEADLINE>Environment Protection</ HEADLINE> <BYLINE> Material waste </BYLINE> <LEAD>&PUBLISHER;</LEAD> <BODY> it means the waste of substance or things from which something else can be made. For example, people throw away the used metal products and buy a new one, so the old metal waste accumulates. At last, they become waste. For example, when people finish reading newspaper, the paper will become waste. When the glass is broken, it also becomes waste. Nobody wants to use a broken window or drink with a broken glass or wear a pair of broken glasses. Once it is broken, it becomes waste. The rate of using plastics is increasing day by day. People use plastic bags because they are convenient. When they get home, they throw the plastics way, paying no attention to the environment. The more convenience plastics brings to us, the more plastic waste is produced. This is called “white pollution” as most plastics are white. Some of our products we use every day are made of rubber, just like the tyres and the bottom part of our shoes. It’s true that rubber plays an important role in our life. However, it also brings us some trouble when it has been used for a long time and becomes old. The old tyres become waste because it can’t break down by nature. This is really a big problem. </BODY>

 <NOTES> Protecting the environment is not one person’s duty; it depends on all of us. What can we do? Maybe a dozen..

 In a word, use what can reuse as much as possible. Remember, environment protection is not one’s duty! </NOTES> </ ARTICLE> </ NEWSPAPER> 3、 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE NEWSPAPER [ <!ELEMENT NEWSPAPER (ARTICLE+)> <!ELEMENT ARTICLE (HEADLINE,BYLINE,LEAD,BODY,NOTES)> <!ELEMENT HEADLINE (#PCDATA)>

 <!ELEMENT BYLINE (#PCDATA)> <!ELEMENT LEAD (#PCDATA)> <!ELEMENT BODY (#PCDATA)>

 <!ELEMENT NOTES (#PCDATA)>

 <!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED> <!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>

 <!ATTLIST ARTICLE DATE CDATA #IMPLIED>

 <!ATTLIST ARTICLE EDITION CDATA #IMPLIED>

  <!ENTITY NEWSPAPER "Vervet Logic Times">

 <!ENTITY PUBLISHER "Vervet Logic Press"> <!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press"> ]>

  <NEWSPAPER> <ARTICLE

 AUTHOR=”&NEWSPAPER;” EDITOR=”&PUBLISHER;” DATE=”2009-6-1”

 EDITION =”&COPYRIGHT;”> <HEADLINE>Environment Protection</ HEADLINE> <BYLINE> Material waste </BYLINE> <LEAD>&PUBLISHER;</LEAD> <BODY> it means the waste of substance or things from which something else can be made. For example, people throw away the used metal products and buy a new one, so the old metal waste accumulates. At last, they become waste. For example, when people finish reading newspaper, the paper will become waste. When the glass is broken, it also becomes waste. Nobody wants to use a broken window or drink with a broken glass or wear a pair of broken glasses. Once it is broken, it becomes waste. The rate of using plastics is increasing day by day. People use plastic bags because they are convenient. When they get home, they throw the plastics way, paying no attention to the environment. The more convenience plastics brings to us, the more plastic waste is produced. This is called “white pollution” as most plastics are white. Some of our products we use every day are made of rubber, just like the tyres and the bottom part of our shoes. It’s true that rubber plays an important role in our life. However, it also brings us some trouble when it has been used for a long time and becomes old. The old tyres become waste because it can’t break down by nature. This is really a big problem. </BODY>

 <NOTES> Protecting the environment is not one person’s duty; it depends on all of us. What can we do? Maybe a dozen..

 In a word, use what can reuse as much as possible. Remember, environment protection is not one’s duty! </NOTES> </ ARTICLE> </ NEWSPAPER>

 第四章 上机题 1、 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Orders" type="ord"/>

 <xs:complexType name="ord"> <xs:element name=" Order">

 <xs:complexType>

 <xs:sequence> <xs:element name="name" type=" xs:string "/> <xs:element name="number" type="numgs"/> <xs:element name="city" type=" xs:string "/> <xs:element name="zip" type=" zipgs"/> </xs:sequence>

 <xs:attribute name=" orderID " type=" idgs " use="required" />

 <xs:attribute name=" orderDate " type="xs: date" use="optional" />

 </xs:complexType>

  </xs:element>

 </xs:complexType>

 <xs:simpleType name=“zipgs”>

 <xs:restriction base=“xs:string”>

  <xs:length value=“6”/>

  <xs:pattern value=“\d{6}”/>

 </xs:restriction> </xs:simpleType>

 <xs:simpleType name=“idgs”>

 <xs:restriction base=“xs:string”>

  <xs:length value=“4”/>

  <xs:pattern value=“ [A]{1}\d{3}”/>

 </xs:restriction> </xs:simpleType>

 <xs:simpleType name=“numgs”>

 <xs:restriction bas e=“xs:positiveInteger”>

  <xs:maxInclusive value=“99”/>

  <xs:minInclusice value=“1”/>

 </xs:restriction> </xs:simpleType>

 </xs:schema>

 2、 <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

 <xsd:attribute name="PRODID" type="pid"/>

 <xsd:simpleType name="pid">

 <xsd:restriction base="xsd:string">

 <xsd:pattern value="[P]{1}\d{3}"/>

 </xsd:restriction>

 </xsd:simpleType>

 <xsd:element name="PRODUCTDATA" type="prdata"/>

 <xsd:complexType name="prdata">

 <xsd:sequence>

  <xsd:element name="PRODUCT">

  <xsd:complexType>

 <xsd:sequence>

 <xsd:element name="PRODUCTNAME" type="xsd:string"/>

 <xsd:element name="DESCRIPTION" type="xsd:string"/>

 <xsd:element name="PRICE" type="xsd:positiveInteger"/>

 <xsd:element name="QUANTITY" type="xsd:nonNegativeInteger"/>

 </xsd:sequence>

 <xsd:attribute ref="PRODID" use="required">

 </xsd:attribute>

 <xsd:attribute name="CATEGORY" type="cat" use="required"/>

  </xsd:complexType>

 </xsd:element>

 </xsd:sequence>

 </xsd:complexType>

 <xsd:si

  9 mpleType name="cat">

 <xsd:restriction base="xsd:string">

 <xsd:enumeration value="Toy"/>

 <xsd:enumeration value="Book"/>

 </xsd:restriction>

  </xsd:simpleType> </xsd:schema>

 3、 <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="PURCHASEORDER " type="pur"/> <xs:complexType name="pur"> <xs:element name=" Order">

 <xs:complexType>

 <xs:sequence> <xs:element name=" DATE " type=" xs: date "/> <xs:element name=" PRODUCTNAME " type=" xs:string "/> <xs:element name=" SUPPLIERNAME " type=" xs:string "/> <xs:element name=" ADDRESS " type=" xs:string "/> <xs:element name=" QUANTITY " type=" xs:positiveInteger "/> <xs:element name=" PRICEPERQTY " type=" xs:positiveInteger "/> </xs:sequence> </xs:complexType>

 </xs:element>

  <xs:attribute name=" ORDERID " type=" xs:string " use="required" />

 <xs:attribute name=" PRODID " type=" xs:string " use="optional" />

 </xs:complexType> </xs:schema>

 第五章 上机题 1、 1)、 <?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">

  <html>

 <head>

 <title>订单信息</title>

  </head>

 <body>

 <h2 align="center">订单</h2>

  <table border="1" cellpadding="0" align="center">

  <tr><th>名称</th><th>数量</th><th>城市</th><th>邮编</th></tr>

  <xsl:for-each select="/ Orders / Order"> <tr>

 <td><xsl:value-of select="name"/></td>

 <td><xsl:value-of select=" number "/></td>

 <td><xsl:value-of select=" city "/></td>

 <td><xsl:value-of select=" zip "/></td>

  <//tr>

 </xsl:for-each>

  </table>

 </body>

  </html>

  </xsl:template> </xsl:stylesheet> 2)、 <?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">

  <html>

 <head>

 <title>订单信息</title>

  </head>

 <body>

 <h2 align="center">订单</h2>

  <table border="1" cellpadding="0" align="center">

  <tr><th>名称</th><th>数量</th><th>城市</th><th>邮编</th></tr>

 <xsl:if test="//Order[@orderID=" A002"]">

  <tr>

 <td><xsl:value-of select="name"/></td>

 <td><xsl:value-of select=" number "/></td>

 <td><xsl:value-of select=" city "/></td>

 <td><xsl:value-of select=" zip "/></td>

  </tr> </xsl:if>

 </table>

 </body>

  </html>

  </xsl:template> </xsl:stylesheet>

 3)、 <?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:template match="/">

  <html>

 <head>

 <title>订单信息</title>

  </head>

 <body>

 <h2 align="center">订单</h2>

  <table border="1" cellpadding="0" align="center">

  <tr><th>名称</th><th>数量</th><th>城市</th><th>邮编</th></tr>

  <xsl:if test=" city [.="北京"]"> <tr>

 <td><xsl:v...

推荐访问:上机 答案 编程

版权所有:文秘范文网 2010-2024 未经授权禁止复制或建立镜像[文秘范文网]所有资源完全免费共享

Powered by 文秘范文网 © All Rights Reserved.。陕ICP备16010436号