[Series] ----- XML XML document format (a)

The classification of XML documents:

 1. Format adverse good (malformed) XML documents: XML documents did not follow the basic norms of XML documents.

 2. good format (well-formed) but invalid XML document: compliance with the basic norms of XML, but does not use an XML document DTD or schema defined semantic constraints.

 3. Effective (valid) XML document: compliance with the basic norms of XML documents, and the use of semantic constraints DTD or schema, and the XML document to comply with the definition of semantic constraints.

XML syntax:

       A complete XML file should contain the following sections:

              - document declaration

              -element

              -Attributes

              - Notes

              -CDATA area, special characters

              - processing instruction (processing instruction)

       Document declaration:

              When writing an XML document, you need to use the document declaration, the declaration of an XML document.

              For example: <? Xml version = "1.0"?>

              Description document's character encoding with the encoding attribute:

              For example: <? Xml version = "1.0" encoding = "GB2312"?>

              Whether independent documentation with the standalone attribute (that is, whether or not reference other resources):

              E.g:

<?xml version=”1.0” encoding=”GB2312” standalone=”?>

       Note: Common XML error

           Common mistakes:

      1. <?xml version=1.0 ?>

      2. <?xml version=“1.0”?>

      3. coding errors

    Common character sets:

      Simplified Chinese: GBK, GB2312

      Traditional Chinese: BIG5

      Western European character: ISO8859-1 

      Common international coding: Unicode, UTF-8

    XML itself save when there will be the default encoding format, please pay attention to coding properties during storage, otherwise it will cause an error when accessing the XML file.

The basic rules of XML elements:

       Element is the basic unit of an XML document, XML document element is a nested layers of elements. The entire XML document from the root element, the root element contains several child elements, and each can contain multiple sub-elements and sub-elements, which can be organized into a complete XML document.

      XML tags are divided into two categories:

              Single marker: <br/>

              Double labeling: <p> </ p>

       XML labeling requirements:

 1. The label name can have letters (containing non-Western European characters), numbers, underscores, in dash, colon and dots, but can not start with a number and underlined the point.

 2. The label name can not contain <>, $, etc.

 3. Try not to label names appear colon, in addition to using the namespace outside.

 4. The tag name can not in any case be combined to xml, XML and the like.

 The label name can not contain spaces

 6. Label names are case sensitive

XML tags nested sub-elements:

XML allows the depth of the nested sub-elements, but need to ensure reasonable nested between the elements can be nested not cross, and XML tags may be nested child elements of a plurality of the same name.

       <a>

              <b></b>

   </a>

For empty elements, it is unacceptable sub-elements can not accept a string content, but it can accept a plurality of attributes.

E.g. <con name = 'bank' />

       For non-empty element can accept a string, when no content contained in the tag is within a space, the space can be considered characters.

       For example: <p> </ p> P at this time is included in a tag character,

              <P> China </ p> Such may contain the string.

Note: There is one and only one root tag in a well-formed xml documents, and XML documents in both spaces and line breaks as the contents of the tag for processing.

Reproduced in: https: //www.cnblogs.com/H_Razor/archive/2011/06/15/xml_02.html

Guess you like

Origin blog.csdn.net/weixin_34348111/article/details/93313343