XML基础

以下内容摘自 http://www.w3schools.com,希望帮助每天都 在使用XML,但却对XML知之甚少的童鞋有所帮助。
因为这个英文比较简单,所以我就直接复制粘贴了,外加了一些小注释。还有,这个英文看起来真的很舒服,还望平时不喜欢看英文的同学不要看到就烦,耐心看完,会对你有帮助的。

What is XML?——神马是XML

XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to carry data, not to display data
XML tags are not predefined(预定义的). You must define your own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation
这里的关键词有:运载数据,自定义标签

XML Documents Form a Tree Structure
XML documents must contain a rootelement. This element is "the parent" of all other elements.
The elements in an XML document form a document tree. The treestarts at the root and branches to the lowest level of the tree.
All elements can have sub elements (child elements):
一个XML文件必须有一个且只能有一个根元素。整个文件的元素会组成一个文档树。想到树我们自然想到这些名词:根,孩子,双亲,兄弟等等,这些称呼在XML中也是适用的。

All XML Elements Must Have a Closing Tag(有开有关)
XML Tags are Case Sensitive(区分大小写的)
XML Elements Must be Properly Nested(正确嵌套)


XML Attribute Values Must be Quoted
XML elements can have attributes in name/value pairs just like inHTML.
In XML, the attribute values must always be quoted.
所有的属性值都要用引号括起来。

Comments in XML(注释形式)
The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->

What is an XMLElement?
An XML element is everything from(including) the element's start tag to (including) the element's end tag.

An element can contain:

other elements
text
attributes
or a mix(混合) of all of the above...

XML Naming Rules——命名规范

XML elements must follow these namingrules:

Names can contain letters, numbers, and other characters
Names cannot start with a number or punctuation character(标点符号)
Names cannot start with the letters xml (or XML, or Xml, etc)
Names cannot contain spaces


Best Naming Practices——最佳命名实践,良好的命名习惯
Make names descriptive. Names with an underscore separator arenice: <first_name>, <last_name>.——有意义的名字
Names should be short and simple, like this: <book_title>not like this: <the_title_of_the_book>.——不要太长
Avoid "-" characters. If you name something"first-name," some software may think you want to subtract name fromfirst.——不要用-,可以用_
Avoid "." characters. If you name something"first.name," some software may think that "name" is aproperty of the object "first."——不要用点(.)
Avoid ":" characters. Colons are reserved to be used forsomething called namespaces (more later).
XML documents often have a corresponding database. A good practiceis to use the naming rules of your database for the elements in the XMLdocuments.
Non-English letters like éòá are perfectly legal in XML, but watchout for problems if your software vendor doesn't support them.——注意编码问题

Avoid XMLAttributes?

Some of the problems with usingattributes are:

attributes cannot contain multiple values (elements can)——一个属性只能有一个值
attributes cannot contain tree structures (elements can)——不具有树结构
attributes are not easily expandable (for future changes)——不易扩展
Attributes are difficult to read andmaintain. Use elements for data. Use attributes for information that is notrelevant to the data.
What I'm trying to say here is that metadata (data about data) 比如说ID, should be stored as attributes, and thedata itself should be stored as elements.
我个人的想法是attribute少打字啊。呵呵。。愚见愚见。。哈哈。。

Well Formed XMLDocuments——这就是构造良好的文档啊
A "Well Formed" XML documenthas correct XML syntax.起码要有正确的语法么。。

The syntax rules were described in theprevious chapters:

XML documents must have a root element
XML elements must have a closing tag
XML tags are case sensitive
XML elements must be properly nested
XML attribute values must be quoted
其实这些上面已经 都 讲过了,在这里算是总结下了,然后让我们知道 ,wow,我们一直都 是在写组织良好的XML啊。。吼吼 。

Valid XML Documents——有效的XML文档是神马样地
A "Valid" XML document is a "Well Formed" XMLdocument, which also conforms to the rules of a Document Type Definition (DTD): The purpose of a DTD is to define the structure of anXML document. It defines the structure with a list of legal elements:

有效的前提 是构造良好的。然后它应该有DTD(文档类型声明),DTD这个我们平时几乎见不到,所以略去不说。


这些就是一些基本的概念东西,如果有时间我会再把有关namespace和XML Schema整理一下 发上来。大家共同学习。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值