惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - Tiu

2010走了,又是一年,留个脚印 Commerce Server 2007 随笔一 2009眨眼间过去了,留个纪念 asp.net ajax随笔二 asp.net中慎用static全局变量 asp.net ajax随笔一 收集的关于依赖注入及Unity application block入门的一些资料 2008最后一篇:总结与展望 文件操作类简介 防止页面在提交的过程中多次点击按钮 第一次使用SQLCLR C#网络编程随笔一 装AJAX.NET 1.0的环境,我遇到个问题,进来解答下 关于邮件群发 asp.net窗中的两个Form问题 URL重写入门 动态从数据库中选择Top 个数 关于在数据层返回SqlDataReader 编写类和子程序的几个原则
XML学习一
Tiu · 2006-12-28 · via 博客园 - Tiu

    以前也看了一些XML的一些知识,但过段时间接着就忘了,这就是“好记性不如烂笔头”了,现在是“好记性不如Blog一下”。虽然说XML已经用了好多了,比如写asp.net程序的时候的web.config文件就是xml形式的,只不过并没有系统的学习过。下面便从基础开始,争取能坚持下去。
    管理XML的历史知识就不介绍了,直接切入正题,下面下列各XML格式的文档:

<?xml version="1.0" ?>
  
<article>
    
<title name="blog">xml学习</title>
  
</article>

这就是一个简单的XML文档了,下面说下XML文档规则:
1.XML文档必须包含在一个根元素中,上例中为 <article>
2.元素不能重叠,也就说下面的文档是错误的:

<?xml version="1.0" ?>
  
<article>
    
<title>xml学习<content></title>
     xml入门
</content>
  
</article>

3.结束标记是必须的,也即有始有终,并不像html中<br>可以单独存在,这在xml中是不允许的
4.xml跟我们写c#程序一样是区分大小写的,即<tiu>与<Tiu>是不同的两个标记
5.xml文档的属性必须用引号引起来,双引号和单引号都可以
6.xml声明,即上面实例的第一行,其还包括两个属性:encoding和standalone,encoding表示采用的编码形式,默认为utf-8,standalone的值为yes或no,默认为no,yes表示不引用任何其他文档
7.注释,xml注释和html的注释一样:<!--注释内容-->
8.还有一些字符:&lt;:小于符号(<);&gt;:大于符号(>),&quot;(双引号),&apos;(单引号),&amp;(&号)
9.还有就是名称空间,作用就是来区分在不同xml文档中定义的相同名字,比如在一个描述商品的文档中也有个title元素,显然那个title的意义和上面例子中title意义不同,如果要组合在一块就要用到名称空间来区分。就像c#中的命名空间可以区分同名的类一样。
    用来查看xml是否合法的就是DTD或xml schema了,它们是来定义xml文档里的元素及相关属性的, 先记这么多,以后再慢慢记 ,下面摘别处一段描述XML Schema的例子,这对XML Schema可以有感性的认识:

下面是一段 XML 模式。它增加了两个约束:<state> 元素的值必须刚好是两个字符长,<postal-code> 元素的值必须与正则表达式 [0-9]{5}(-[0-9]{4})? 相匹配。它更清楚地表达了有效的文档看起来是什么样子。下面是模式:


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="address">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="name"/>
<xsd:element ref="street"/>
<xsd:element ref="city"/>
<xsd:element ref="state"/>
<xsd:element ref="postal-code"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="name">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="title" minOccurs="0"/>
<xsd:element ref="first-Name"/>
<xsd:element ref="last-Name"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="title" type="xsd:string"/>
<xsd:element name="first-Name" type="xsd:string"/>
<xsd:element name="last-Name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>

<xsd:element name="state">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:length value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

<xsd:element name="postal-code">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{5}(-[0-9]{4})?"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:schema>