
The syntax of Xml
• A XML file is divided into the following parts:
##– Document Declaration
– Element
– Attributes
– Comments
– CDATA area, special characters
– Processing instructions (processing instruction)
Declaration of Xml
The simplest declaration
##Encoding attribute : Character encoding if not specified, the default is UTF-8 encoding
##Common character setSimplified Chinese:
GBKor GB2312Traditional Chinese
: BIG5Western European characters
:ISO8859-1##Universal international encoding:Unicode UTF-8
Demonstration case:
##
<中国>
中国>Cause of error Yes:
Encoding error
|
|
Document when the character set is wrong
| document What is saved is .xml UTF-8 Default encodingANSI China
|
|
Encoded into binary code 00 11
|
|
Standalone:Specify whether the document needs to reference other resources,The attribute value is only: yes or no ##Yes:Independent No:Not independent
XML file is the same as HTML file, it is actually a text file. Obviously everyone will understand immediately that the most common tool for creating XML files is the same as HTML, which is "Notepad". In addition to "Notepad", of course there are some more convenient tools, such as XML Notepad, XML Pro, and CLIP! XML Editor, etc. One of the major features of these tools is that they can check whether the XML file you create complies with the XML specification. However, these tools are currently only available in English and require payment. Of course, you can still use tools such as FrontPage and DreamWeaver, but they are not very convenient to use. With the gradual popularity of XML, I believe that very useful tools for creating XML files will appear in the near future. Now let's use "Notepad" to create our XML file. First look at an XML file: Example 1 ##〈?xml version="1.0" encoding="gb2312" ?〉 〈References〉
Among them, version is the standard version number used by this XML file, which is required; encoding specifies the character type used in this XML file, which can be omitted. When you omit this statement, the following The character code must be a Unicode character code (it is recommended not to omit it) . Because we are using GB2312 character code in this example, the encoding statement cannot be omitted. There are also some declaration statements in the preamble of the file, which we will introduce later. The rest of the file belongs to the file body, and the content information of the XML file is stored here.
〈B〉〈H〉XXXXXXX〈/B〉〈/H〉,〈B〉 and 〈H〉
XmlBasic rules for elements ##Elements are part of the xml document The basic unit , xml document is composed of elements nested layer by layer. The entire xml document starts from the root element,The root element contains several sub-elements,and each sub-element can contain several sub-elements,So that a xml document can be formed. Xml Tag syntax: ## 1, ## The tags of #Xml are divided into two categories: #Single tag:<中国/>#Double mark: <中国>中国>## 2, xml tag requirements: ## 1. Tag names can contain letters ( includes non-Western European characters , numbers, underscores (_), and underscores (-), colon (:) and period (.) form , but cannot start with numbers, dashes or periods. 2, tag name cannot contain <, ,,,$ and other symbols 3, try not to have English colons (:), in label names unless you are using a namespace. 4, tag name cannot start with any combination of upper and lower case characters such as xml, , etc. #5, tag name cannot contain spaces. 6, tag names are case-sensitive 3, xml Tag nested sub-elements: xml allows deep nesting of sub-elements, as long as reasonable nesting between elements is ensured That is .And the xml element can nest multiple sub-elements with the same name,these multiple sub-elements are in order. First:xml ##<China > ## <Beijing> ; <Haidian/> # ; <Chaoyang>Chaoyang >## < Chaoyang>Chaoyang>## Beijing >## China> ##Secondxml: ##<China> ## <Beijing> ## <Chaoyang>Chaoyang> ; ##/>## Beijing >中国> ##4, empty element: empty element cannot accept child elements, also cannot accept string content. ## xml: # And can accept multiple attributes ## For example, an empty element accepts attributes: 5、字符数据 Struts2开发详解
对于XML标签中出现的所有空格和换行,XML解析程序都会当作标签内容进行处理 如果文本字符中包含了一些特殊的字符,例如<和&由于这些字符都有特殊的含义,因此直接在xml文档中使用该字符串将引起文档的混乱。 <表达式>
<比较符>1+3<6比较符> 表达式>
代表的是文本字符串中包含了特殊的字符
有以下两种方法解决: 1、 使用实体引用:用另一个特殊符号代替这些特殊符号 2、使用CDATA标记:将整个文档定义成字符串。 1、 使用实体引用
<表达式> <比较符>1+3&<6比较符> 表达式> 上面的红色的<产生了干扰
解决如下:
<表达式> <比较符>1+3<6比较符> ; Tag Under the special tagCDATA,all special characters,are even valid elements will be treated as simple strings. Entity references also lose their effect and become direct text. The syntax format of CDATA is as follows: ##< ![CDATA[Text content]]> ### <Expression> +3<6 ]]> # Expression> # Note: Since the xmldocument will not perform any parsing of the CDATA tag content at all ,, therefore any content can be placed within CDATA, where The content is never wrong. 1, Comment ##XmlThe document can also add character data for explanation,These strings used for interpretation will not be processed by the xml parser. These explanatory texts are called notes. The documentation comments of Xml are exactly the same ashtml. XmlThe syntax format of comments is as follows: Comments for Xml are allowed to contain elements and tags. Note: 1, Xml comments cannot be placed in the tag body.2, Do not put thexml document before the xml document declaration xml document The declaration is always on the first line 3, Do not use double underscores in comments (--) ….. ##2, Processing instructions Processing instructions, referred to as PI (processing instruction). Processing instructions are used to instruct the parsing engine how to parse the XML document content. Processing instructions are used to provide information to applications that process xml documents, telling the processor how to process the document. A complete xml document processing program, can read the xml document processing instructions, and perform corresponding processing according to the processing instructions,Or pass it to the next program. XmlThe format of the processing instruction is as follows: Processing instruction name processing Command information?> ##3、 Attribute xmlCharacteristics of attributes: 1, xmlThe attribute of the element must have an attribute value,The attribute value must be enclosed in quotation marks. 2, The same xml element cannot have multiple attributes with the same name ##3, XmlThere is no order among the multiple attributes in the element. book itself has isbn book_name price The properties of There must be a root element. The overall structure of the document##1, (There is and only one)##2, The element must end reasonably 3, Elements must be nested reasonably 4, The attributes of elements must have attribute values As long as the above conditions are not met, it is a poorly formatted documentxmlDocument ##As long as the above conditions are met, it is a well-formatted documentxmlDocument and comply with dtd or schema xml document. XmlDocument is a standard structured document that can be converted into DOM (Document Object Model) ,The root node corresponds to the root node of the DOM tree.
#computer
#…………
##computer
#name
Notice: Must have a root tag and the root tag must be unique The start tag and the end tag need to be used in pairs Marks cannot be used interchangeably Empty markers can be written in the form of " <tag name/>"
The above are the crazy XML study notes (2)--------- ----Format required content, please pay attention to the PHP Chinese website (m.sbmmt.com) for more related content!
|