xml复习之代码篇

XML 复习之 代码篇

HTML常用标签

常用标记

 <html></html> HTML文件必须的标记
 <head></head> 指定HTML网页的文件信息
 <title></title> 网页标题
 <body></body> 网页主体 文本信息
 <h(n)></h(n)>网页的子标题 从1到6
 <br> 换行显示
 <hr> 水平线

文字标示

<small></small>小字号
<big></big>大字号
<font size=n>字体大小
<basefont size=n>默认字体的大小
<b></b>粗体显示
<i></i>斜体显示
<u></u>下划线
<strike></strike>删除线
<sub></sub>下标
<sup></sup>上标

列表

<dir></dir>以列表方式显示
<menu></menu>以列表方式显示
<ul></ul> 
    <ul type= f>
         f = disk 实心圆
         f = circle 空心圆
         f = square 实心方框 

<ol></ol>
    <ol type =f>
        f =A 以大写字母排序
        f =a 以小写字母排序
        f=I 以大写罗马字母排序
        f=i 以小写罗马字母排序
        f=1 以阿拉伯数字排序
    <ol start=n>
        n为编号的起始号

表格

<table></table> 表明表格的范围
    属性
        border 表格框线宽度 
        width 表格的宽度 可以是数字也可以是百分比
        height 表格的高度 可以是数字也可以是百分比
        cellspacing 单元格线的宽度
        cellpeddeing 单元格和数据之间的距离
<caption></caption> 表格标题
    align:
        top 标题在表格上
        bottom 标题在表格下
<tr></tr> 表格一行的内容 必须在<tr></tr>中 文字突出显示
<th></th> 表格栏目行中的一项 必须在<tr></tr>中 文字正常显示
    align:
        left 居左
        right 居右
        center 居中
    nowrap:
        数据较多时不换行显示
    width:
        指定宽度
    valign:
        top 文字显示在本行的偏上方位置
        middle 文字显示在本行的中间位置
        bottom 文字显示在本行的偏下方位置
    cospan:
        实现单元格的横向合并 n为合并的单元格的数量
    rowspan:
        实现单元格的纵向合并 n为合并的单元格的数量
<td></td>

色彩

<body></body>
    text= 文本的颜色
    link= 超链接的颜色
    vlink= 鼠标指向的超链接文字
<font color=> 设置某一类文字的颜色

<table bgcolor= > 表格的背景颜色
<td bgcolor= > 某一行的背景颜色
<th bgcolor= > 栏目行的背景颜色
<hr color= > 水平线的颜色

链接

<a href=> 显示内容 </a> 页面链接

<a #标记名>内容</a> 本地链接标记
<a name=标签名> 显示内容</a> 本地链接目标处
<a href="mailto:****@***.***">***</a> 邮箱链接

XML

特殊字符的使用

    <?xml version="1.0" encoding="utf-8" ?>
    <book bookcatagory="&lt;文艺&gt;">
        <bookinfo>
            <title>计算机导论</title>
            <author>丁跃潮等</author>
            <publish>
                <publisher>高等教育出版社</publisher>
            </publish>
            <price>18.00</price>
        </bookinfo>
    </book>

复合元素的用法

       <?xml version="1.0" encoding="utf-8" ?>
        <!DOCTYPE bookinfo[
        <!ELEMENT bookinfo (title,author,publish,price)>
        <!ELEMENT title (#PCDATA)>
        <!ELEMENT author (#PCDATA)>
        <!ELEMENT publish (publisher,ISBN,pubdate)>
        <!ELEMENT publisher (#PCDATA)>
        <!ELEMENT ISBN (#PCDATA)>
        <!ELEMENT pubdate (#PCDATA)>
        <!ELEMENT price (#PCDATA)>
        ]>
        <bookinfo>
            <title>计算机导论</title>
            <author>丁跃潮等</author>
            <publish>
                <publisher>高等教育出版社</publisher>
                <ISBN>7-04-014768-8</ISBN>
                <pubdate>2004.6</pubdate>
            </publish>
            <price>19.7</price>
        </bookinfo>

元素组

    <?xml version="1.0" encoding="utf-8" ?>
        <!DOCTYPE bookinfo[
        <!ELEMENT maininfo (title,author,price)>
        <!ELEMENT bookinfo (booknumb,maininfo+)>
        <!ELEMENT booknumb (#PCDATA)>
        <!ELEMENT title (#PCDATA)>
        <!ELEMENT author (#PCDATA)>
        <!ELEMENT price (#PCDATA)>
        ]>
        <bookinfo>
            <booknumb>2</booknumb>
            <maininfo>
                <title>计算机导论</title>
                <author>丁跃潮等</author>
                <price>19.7</price>
            </maininfo>
        </bookinfo>

外部二进制形式文件的使用

     <?xml version="1.0" encoding="utf-8" ?>
        <!DOCTYPE customers[
        <!ELEMENT customers (customers*)>
        <!ELEMENT customer (username,password,picture)>
        <!ELEMENT username (#PCDATA)>
        <!ELEMENT password (#PCDATA)>
        <!ELEMENT picture EMPTY>
        <!ATTLIST picture pic ENTITIES #REQUIRED>
        <!ATTLIST customer ID ID #REQUIRED>
        <!NOTATION jpg SYSTEM "mspaint.exe">
            <!ENTITY pic1 SYSTEM "a.jpg" NDATA jpg>
            <!ENTITY pic2 SYSTEM "b.jpg" NDATA jpg>
            <!ENTITY pic3 SYSTEM "c.jpg" NDATA jpg>
            <!ENTITY pic4 SYSTEM "d.jpg" NDATA jpg>
        ]>
       <customers>
            <customer ID="c0500103">
                <username>cheaperget</username>
                <password>123456789</password>
                <picture pic ="pic1 pic2" />
            </customer>
            <customer ID="c05002208">
                <username>dreamingboy</username>
                <password>223456789</password>
                <picture pic ="pic3 pic4" />
            </customer>
        </customers>

Schema

XML文档
<?xml version="1.0" encoding="utf-8" ?>
    <book isbn="0-764-58007-8">
        <title>三国演绎</title>
        <author>罗贯中</author>
        <price>80</price>
        <resume>........................省略了。。。。。。。。。。。。</resume>
        <recommendation>经典好书</recommendation>
        <publish>
            <publisher>文艺出版社</publisher>
            <pubdate>1998.10</pubdate>
        </publish>
    </book>
信息模式定义
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="book">
    <xsd:complexType>
    <xsd:sequence>
        <xsd:element name="title" type="xs:string" />
        <xsd:element name="author" type="xs:string" />
        <xsd:element name="price" type="xs:integer" />
        <xsd:element name="resume" type="xs:string" />
        <xsd:element name="recommendation" type="xs:string" />
        <xsd:element name="publish" minOccurs="0" maxOccurs="unbounded" >
            <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="publisher" type="xs:string" />
                <xsd:element name="pubdate" type="xs:date" />
            </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="isbn" type="xs:string">
    <xsd:complexType>
</xsd:element>
</xsd:schema>
用户自定义简单类型 
<xsd:simpleType name="myint">
    <xsd:restiction base="xsd:integer">
        <xsd:minInlusive value="100">
        <xsd:maxInclusive value="999">
    </xsd:restiction>
</xsd:simpleType>
用户自定义枚举类型
<xsd:simpleType name="category">
    <xsd:restiction base="xsd:token">
        <xsd:enumeration value="小说">
        <xsd:enumeration value="散文">
        <xsd:enumeration value="传记">
        <xsd:enumeration value="诗歌">
        <xsd:enumeration value="武侠">
        <xsd:enumeration value="纪实">
    </xsd:restiction>
</xsd:simpleType>
联合类型
<!-- Schema Fragment -->
<xsd:simpleType name="gradeUnion">
<xsd:union>
    <xsd:simpleType name="scoreType">
        <xsd:restriction base="integer">
            <xsd:minInlusive="0" />
            <xsd:maxInclusive="100" />
        </xsd:instriction>
    </xsd:simpleType>

    <xsd:simpleType name="gradeType">
        <xsd:restriction base="token">
            <xsd:enumeration value="优秀" />
            <xsd:enumeration value="良好" />
            <xsd:enumeration value="及格" />
            <xsd:enumeration value="不及格" />
        </xsd:restiction>
    <xsd:simpleType>
</xsd:union>
</simpleType>
复杂类型
<xsd:element name="book">
    <xsd:complexType>
    <xsd:all>(xsd:sequence/xsd:choice[minOccurs maxOccurs = "unbounded"]表示允许任意数量的子元素以任意顺序出现)
        <xsd:element name="title" type="xsd:string" />
    </xsd:all>
    </xsd:complexType>
</xsd:element>

外联数据岛

<HTML>
    <head>
        <title> 外联数据岛</title>
    </head>
    <body>
        <xml id="XMLdata" src = "data.xml"> </xml>
        <h2 align="center">
            <font size="3">数据显示</font>
        </h2>
        <table datasrc ="#XMLdata" border="1" align="center">
            <thead>
                <th>customerID</th>
                <th>order_data</th>
                <th>order_status</th>
                <th>items</th>
            </thead>
            <tr>
                <td><span datafld="coutomerID"></span></td>
                <td><span datafld="oder_data"></span></td>
                <td><span datafld="order_status"></span></td>
                <td><table datarc="#XMLdata" datafld="items">
                        <tr><td><table border="1" datasrc="#XMLdata" datafld = "item">
                            <thead>
                                <th>bookID</th>
                                <th>quantity</th>
                                <th>item_status</th>
                            </thead>
                            <tr>
                                <td><span datafld="bookID"></span></td>                          <td><span datafld="quantity"></span></td>
                                <td><span datafld="item_status"></span></td>
                            </tr>
                        </table></td></tr>
                </table></td>
            </tr>
        </table>
    </body>
</html>

分页显示XML数据源的数据

<OBJECT classid="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" id = "XMLDSO" height="0" width="0"></OBJEXT>
<HTML>
    <head>
        <title>分页显示书本信息</title>
    </head>
    <script language="JavaScript">
        var XMLdoc = XMLDSO.XMLDocument;
        XMLDSO.async = false;
        XMLdoc.load("data.xml");
    </script>

    <body>
        <center><b><font size="3">分页显示书本信息</font></b></center>
        <table id =tblbooks datasrc="#XMLDSO" >
            <thread>
                <th>书名</th><th>类别</th><th>书号</th>
                <th>作者</th><th>出版社</th><th>定价</th><th>剩余量</th>
            </thread>
            <tr>
                <td><span datafld="title"></span></td>
                <td><span datafld="bookcategory"></span></td>
                <td><span datafld="ISBN"></span></td>
                <td><span datafld="author"></span></td>
                <td><span datafld="publisher"></span></td>
                <td><span datafld="price"></span></td>
                <td><span datafld="remain"></span></td>
            </tr>
        </table>
        <hr>
        <cenrter>
            <input type="button" onclick="tblbooks.preiousPage()" value="上一页">
            <input type="button" onclick="tblbooks.nextPage()" value="下一页">
            每一页<input type=text value="3" size="5" onblur="tblbooks.dataPageSize = this.value;">笔
        </center>
    </body>
</html>

XSL

网站购物车 文档

data.xml
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="tran.xsl" ?>
<shoppingcart>
    <customer>
        <name>赵子龙</name>
        <email>Jerry@eamil.com</email>
        <zipcode>361021</zipcode>
        <address>中国厦门</address>
    </customer>
    <shoppingitem>
        <item>
            <itemNo>1101</itemNo>
            <itemName>三国演义</itemName>
            <price>80.00</price>
            <publisher>文艺出版社</publisher>
        </item>
    </shoppingitem>
</shoppingcart>
tran.xsl

<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
        <html>
            <head>
                <title>书籍订单</title>
                <style>      </style>
            </head>
            <xsl:apply-templates />
        </html>
    </xsl:template>

    <xsl:template match="shoppingcart">
        <body> <xsl:apply-templates /></body>
    </xsl:template>

    <xsl:template match="shoppingcart/customer">
        <div><xsl:value-of select="name" /></div>
        <div><xsl:value-of select="email" /></div>
        <div><xsl:value-of select="address" /></div>
        <div><xsl:value-of select="zipcode" /></div>
    </xsl:template>

    <xsl:template match="shoppingcart/shoppingitem">
        <table>
            <thread>
                <td><b>编号</b></td>
                <td><b>书名</b></td>
                <td><b>价格</b></td>
                <td><b>出版社</b></td>
            </thread>
            <xsl:for-each select="./item" order-by="itemNo">
                <tr>
                    <td><b><xsl:value-of select="itemNo"></b></td>
                    <td><b><xsl:value-of select="itemName"></b></td>
                    <td><b><xsl:value-of select="price"></b></td>
                    <td><b><xsl:value-of select="publisher"></b></td>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>

转载于:https://www.cnblogs.com/cuizhen/p/9233282.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值