XML Basics

1, XML (eXtensible Markup Language)

1. Introduction:

Extensible markup language is a tag language. Commonly used for interface language use.

2. The difference between XML and html:

① XML tag: it is a user-defined tag, and the structure is separated from the style; Designed to transmit and store data.

② HTML tag: it is a fixed tag, which combines structure and style; Designed to display data.

3. Application of XML:

msn stores chat records locally in xml.

4. Development history of XML and html:

It appeared in 1998 to replace html. Because it takes a lot of human and financial resources, the cost is relatively high, and the replacement is not successful in the end.

xhtml: the internal technology is xtml, and the tags are html.

5. Functions of XML:

① It can be used as a small database: msn chat keeps chat record information locally through xml files.

② It can be used as an interface service in the website.

③ It can be used as a configuration file: for example, configure the host name, user name and password of the database in xml in the project.

6. Syntax Standard of XML:

1) Declare a processing instruction <? xml version="1.0" encoding= "utf-8"?>;

The xml content can be interpreted and run directly by the browser. When you see the processing instructions, you will automatically call the xml interpreter.

Explanation of header file attributes:
- version: version 1.0 of XML (version used in the text) 1.1
- encoding: xml code GBK UTF-8 iso8859-1 (excluding Chinese), etc. this code specifies the code to read the file content when opening the file, not the saved code
- standalone: need to rely on other files yes/no

2) The tree structure of XML document has and only has one root node, and the root node must be written.

3) The label must be closed

4) Consistent case of labels (lowercase is recommended)

5) All attributes are in lowercase. The attribute must have a value and the value must have quotation marks (both single and double can be used)

6) Labels can be nested but not crossed

7) Special symbols use symbol entities (single quote & apos; double quote & quote; Space & nbsp; Symbol & ANP;)

8) Large sections have special content <! [CDATA []] > indicates. The interpreter treats special characters as text content instead of labels

9) Empty tag closed / single tag.

10) xml tag name component:

11) In xml, line breaks and spaces are parsed as content. The following two kinds represent different content.


12) Notes: <! --- >, Comments cannot be nested or placed on the first line.




2, How XML files are parsed

1.SAX reading mode: according to the needs of programmers, only a few tags are loaded into memory at a time. Event driven, parsing while reading, parsing line by line from top to bottom.

Advantages: save memory.

Disadvantages: low efficiency when reading a large amount of label information.

2.DOM reading method: load all contents of all xml documents at one time and load them into memory. According to the hierarchical structure of xml, a tree structure is allocated in memory to encapsulate xml tags, attributes and text as objects.

Advantages: when reading a large amount of label information, it runs fast because it is located in memory.

Disadvantages: waste of memory.


3, XML constraint document

1. Functions of XML constraint document:

1) Set the [tag type name] declared in the current XML document

2) Set the [attribute name] that can appear in the tag

3) Set the parent-child relationship and sibling relationship between labels

2.XML constraint document classification:

1) DTD constraint document (simple constraint document): suffix dtd

For example:

<?xml version="1.0" encoding="UTF-8"?>
<!-- The first sentence is to declare that this is a xml file-->
	1.<!ELEMENT Label type name>: Statements can be xml The label type name that appears in the document
	2.<!ATTLIST Label type name property name>:Declares that attribute names can be used inside the current tag
	3.<!ELEMENT Label type name(Sub bid signature?)>:Child labels can appear inside the parent label or not. If they appear, they can only appear once.
	4.<!ELEMENT Label type name(Sub bid signature+)>:The child label must appear inside the parent label and can appear multiple times
	5.#PCDATA indicates that the current tag has no child tags
	6.<!ELEMENT Label type name(Sub bid signature*)>:Sub tags can appear or not, and can be repeated
	7.<!ELEMENT Label type name(Sub bid signature)>: Must appear, only once
	8.<!ELEMENT Label type name(Sub bid signature|Subtag 2)>:One of these two sub tags must appear
<!-- use DTD The following code must be imported into the target file before the document: import constraint

<!DOCTYPR web-app SYSTEM "web-app_2_3.dtd">


<!ELEMENT web-app (servlet*,servlet-mapping*,welcome-file-list?)>
<!ELEMENT servlet (servlet-name,description?,(servlet-class|jsp-file))>
<!ELEMENT servlet-mapping (servlet-name,url-pattern)>
<!ELEMENT servlet-name (#PCDATA)>
<!ELEMENT servlet-class (#PCDATA)>
<!ELEMENT url-pattern (#PCDATA)>
<!ELEMENT jsp-file (#PCDATA)>
<!ELEMENT description (#PCDATA)>

<!ELEMENT welcome-file-list (welcome-file+)>
<!ELEMENT welcome-file (#PCDATA)>

<!ATTLIST web-app version CDATA #IMPLIED>
<!ATTLIST web-app name CDATA #IMPLIED>

Then the configured xml file must be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app SYSTEM "web-app_2_3.dtd">
<!--Introduce external dtd constraint -->
<web-app version="3.0" name="13">
		<servlet-name>A	</servlet-name>

2) SHEMA constraint document (Advanced constraint document): affixing xsd

3. Difference and connection

1. Two constraint documents cannot appear at the same time

2.SHEMA supports prefix names, multiple When XSD files exist, they can be distinguished.














Keywords: xml

Added by Tubby on Fri, 04 Mar 2022 03:51:58 +0200