XML

2020-07-16  本文已影响0人  那些傲慢的404

XML 全称是Extensible Markup Language,可扩展标记语言。

XML 声明

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

XML实体引用

截屏2020-07-16 下午10.11.50.png

CDATA标签

<lesson>
    <content>
        <![CDATA][
        <body>
            <a href="index.html">首页</a>
        </body>
        ]
    </content>
</lesson>

DTD

DTD节点定义
<!ELEMENT index(employee)>
<!ELEMENT employee(name, age)>
<!ELEMENT name(#PCDATA)>
DTD定义节点数量
<!ELEMENT index(employee+)>
<!ELEMENT index(employee*)>
<!ELEMENT index(employee?)>

XML中引用DTD文件

<!DOCTYPE index SYSTEM "index.dtd">

XML Schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="hr">
        <!-- complexType标签含义是复杂节点,包含子节点时必须使用这个标签 -->
        <complexType>
            <sequence>
                <element name="employee" minOccurs="1" maxOccurs="9999">
                    <complexType>
                        <sequence>
                            <element name="name" type="string"></element>
                            <element name="age">
                                <simpleType>
                                    <restriction base="integer">
                                        <minInclusive value="18"></minInclusive>
                                        <maxInclusive value="60"></maxInclusive>
                                    </restriction>
                                </simpleType>
                            </element>
                            <element name="salary" type="integer"></element>
                            <element name="department">
                                <complexType>
                                    <sequence>
                                        <element name="dname" type="string"></element>
                                        <element name="address" type="string"></element>
                                    </sequence>
                                </complexType>
                            </element>
                        </sequence>
                        <attribute name="no" type="string" use="required"></attribute>                  
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>  
</schema>
在XML中引入 XML Schema
<index xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="index.xsd">
上一篇下一篇

猜你喜欢

热点阅读