黑马程序员_Schema解析XML文档详解

---------------------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! --------------------



1.    书写简单的 Schema 文档

     创建 XML 文档 studentschema.xml如下:

<?xml version="1.0"encoding="GB2312"?>

<学生 学号="1">

<姓名>张三</姓名>

<性别>男</性别>

<年龄>20</年龄>

</学生>

<学生 学号="2">

<姓名>李四</姓名>

<性别>女</性别>

<年龄>19</年龄>

</学生>

<学生 学号="3">

<姓名>王二</姓名>

<性别>男</性别>

<年龄>21</年龄>

</学生>

<学生 学号="4">

<姓名>王二</姓名>

<性别>男</性别>

<年龄>21</年龄>

</学生>

</学生名册>

 

     新建文本文件,首先是 XML 声明代码

<?xml version="1.0"encoding="GB2312"?>

 

     添加 Schema 声明

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"elementFormDefault="qualified">

… …

</xs:schema>

 

     添加“学生名册”元素定义

<xs:element name="学生名册">

<xs:complexType>

<xs:sequence>

<xs:element ref="学生" maxOccurs="unbounded"/>

</xs:sequence>


</xs:complexType>

</xs:element>

 

     “学生名册”元素之后添加“学生”元素定义

<xs:element name="学生">

<xs:complexType>

<xs:sequence>

<xs:element ref="姓名"/>

<xs:element ref="性别"/>

<xs:element ref="年龄"/>

</xs:sequence>

<xs:attributename="学号"use="required" type="xs:int"/>

</xs:complexType>

</xs:element>

 

     参考上述方法依次添加“姓名”、“性别”、“年龄”元素定义

<xs:element name="姓名" type="xs:string"/>

<xs:element name="性别">

<xs:simpleType>

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

<xs:enumeration value="女"/>

<xs:enumeration value="男"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:element name="年龄"type="xs:int"/>

 

     文件保存为 studentschema.xsd

 

     在 studentSchema.xml文件中加入对 schema 文件的引用

<学生名册 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="studentschema.xsd">

 

     添加一条不符合约束的数据

     用 XMLSPY 观察出错信息

 

2.    根据 Schema 书写 XML 文档

     创建 schema 文件 company.xsd 如下

<?xml version="1.0"encoding="GB2312"?>

<xs:schema                                                xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:element name="联系人列表">

<xs:complexType>

<xs:sequence>


<xs:element ref="联系人" maxOccurs="unbounded"/>

</xs:sequence>

<xs:attributename="公司"type="xs:string"use="required"/>

</xs:complexType>

</xs:element>

<xs:element name="联系人">

<xs:complexType>

<xs:sequence>

<xs:element ref="姓名"/>

<xs:element ref="公司"/>

<xs:element ref="电话"/>

<xs:element ref="地址"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="公司"type="xs:string"/>

<xs:element name="邮编"type="xs:int"/>

<xs:element name="地址">

<xs:complexType>

<xs:sequence>

<xs:element ref="街道"/>

<xs:element ref="城市"/>

<xs:element ref="省份"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="城市">

<xs:simpleType>

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

<xs:enumeration value="上海"/>

<xs:enumeration value="北京市"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

<xs:element name="姓名"type="xs:string"/>

<xs:element name="电话"type="xs:string"/>

<xs:element name="省份">

<xs:simpleType>

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

<xs:enumeration value="上海"/>

<xs:enumeration value="北京"/>

</xs:restriction>

</xs:simpleType>

</xs:element>


<xs:element name="街道" type="xs:string"/>

</xs:schema>

 

     分析上述 Schema 文档 根节点元素:联系人列表(包含子元素联系人、属性公司) 联系人元素含姓名、公司、电话、地址四个子节点元素地址节点元素含有三个子元素:街道、城市和省份

 

     创建针对上述 Schema 的 XML 文档,示例:

<?xml version="1.0"encoding="GB2312"?>

<联系人列表公司="A集团">

<联系人>

<姓名>张三</姓名>

<公司>A 公司</公司>

<电话>(021)5555666</电话>

<地址>

<街道>5 街</街道><城市>上海市</城市><省份>上海</省份>

</地址>

</联系人>

<联系人>

<姓名>王三</姓名>

<公司>B 公司</公司>

<电话>(021)5555777</电话>

<地址>

<街道>87 街</街道><城市>上海市</城市><省份>上海</省份>

</地址>

</联系人>

</联系人列表>










------------------------ <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------------------




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Implement natural language processing applications with Python using a problem-solution approach. This book has numerous coding exercises that will help you to quickly deploy natural language processing techniques, such as text classification, parts of speech identification, topic modeling, text summarization, text generation, entity extraction, and sentiment analysis. Natural Language Processing Recipes starts by offering solutions for cleaning and preprocessing text data and ways to analyze it with advanced algorithms. You’ll see practical applications of the semantic as well as syntactic analysis of text, as well as complex natural language processing approaches that involve text normalization, advanced preprocessing, POS tagging, and sentiment analysis. You will also learn various applications of machine learning and deep learning in natural language processing. By using the recipes in this book, you will have a toolbox of solutions to apply to your own projects in the real world, making your development time quicker and more efficient. What You Will Learn Apply NLP techniques using Python libraries such as NLTK, TextBlob, spaCy, Stanford CoreNLP, and many more Implement the concepts of information retrieval, text summarization, sentiment analysis, and other advanced natural language processing techniques. Identify machine learning and deep learning techniques for natural language processing and natural language generation problems Who This Book Is For Data scientists who want to refresh and learn various concepts of natural language processing through coding exercises.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值