XML, DTD, Schema, dom4j resolve

XML: eXtensible Markup Language

The HTML and XML syntax similar, but the elements are fixed in HTML, and XML tags can be customized by the user.

XML syntax:

XML document declaration

1. The documentation states must begin with <xml, to??> End ;

2. The documentation states that the document must be from 0 0 row start position column :

3. The documentation states that only property :

a) versioin: Specifies the XML document versions.

b) encoding: specify the encoding of the current document. Optional attribute, the default value yes. utf-8:

Element element

1. element is the XML most important part of the document,

2. The structure began to label the common elements, elements of the body, an end tag.

3. elements of the body : the element body can be an element, it can be text.

4. Empty elements : empty element tag is only the beginning, but no end tag, but the elements must be closed own referrals.

5. element name :

a) case-sensitive

b) You can not use spaces, you can not use a colon :

c) it is not recommended to XML, xml, beginning Xml

6. Formatting good XML document must have only one root element.

Attributes

1. The property is part of the element, it must appear at the beginning of the label elements

2. Definition Format attribute : attribute name = attribute value, wherein the attribute value must be a single or double quotes primer

3. An element may have a O ~ N attributes, but can not appear in an element of the same name attribute

4. Attribute names can not use spaces, colon and other special characters, and must start with a letter

Note

XML comments and HTML same, that is, " <! -" Start with "-> " end. Notes content will be XML parser ignored !

Escape character

XML escape character and HTM L the same.

Because many symbols have been XML used in the document structure, so I want to use these symbols must be used in an escape character element or attribute values .

CDATA area

When a large number of escape characters appear in the xml the document, the cause xml document readability significantly reduced. Then if you use CDATA sections will be better.

CDATA段中出现的“<”、“>’,、“””、“‘”、“&”,都无需使用转义字符。这可以提高xml文档的可读性。

   CDATA段中不能包含“]]>”,即CDATA段的结束定界符。

DTD:文档类型定义,用来约束XML文档。规定XML文档中元素的名称,子元素的名称及顺序,元素的属性等。

DTD语法:

1.内部DTD,在XML文档内部嵌入DTD,只对当前XML有效。

2.外部DTD——本地DTD,DTD文档在本地系统上,公司内部自己项目使用。

3.外部DTD——公共DTD,DTD文档在网络上,一般都有框架提供。

Schema约束:

Schema是新的XML文档约束。

Schema要比DTD强大很多,是DTD替代者

Schema本身也是XML文档,但Schema文档的扩展名为xsd,而不是xml。

Schema功能更强大,数据类型更完善。

Schema支持名称空间。

 

dom4j解析:

解析方式和解析器:

开发中比较常见的解析方式有三种,如下:

1.DOM:要求解析器把整个XML文档装载到内存,并解析成一个Document对象。

a) 优点:元素与元素之间保留结构关系,故可以进行增删改查操作。

b) 缺点:XML文档过大,可能出现内存溢出显现。

SAX:是一种速度更快,更有效的方法。它逐行扫描文档,一边扫描一边解析。并以事件 驱动的方式进行具体解析,每执行一行,都将触发对应的事件。

a) 优点:处理速度快,可以处理大文件

b) 缺点:只能读,逐行后将释放资源。

3. PULL:  Android内置的XML解析方式,类似SAX

解析器:就是根据不同的解析方式提供的具体实现。

 

Guess you like

Origin www.cnblogs.com/boss-H/p/11105675.html