Getting Started with Javaweb 20160301---XML

Source: Internet
Author: User
Tags cdata file url naming convention processing instruction

First, XML syntax
1. Document Declaration
Used to declare the basic attributes of XML to direct the parsing engine to parse the current XML
Typically an XML is included and can contain only one document declaration
The XML document must be at the top of the entire XML and cannot have any content until the document is declared

<?xml version= "1.0"? >--version is an attribute that must exist, indicating the version of the specification that the current XML conforms to, and the current location is 1.0.
<?xml version= "1.0" encoding= "Utf-8"? >--encoding is used only to parse the encoding used by the engine when parsing XML, it is important to ensure that the XML format of the data used in the encoding and parsing must be used in the same encoding and resolution, There's no problem with garbled characters.
<?xml version= "1.0" encoding= "Utf-8" standalone= "Yes"/>--standalone property is used to indicate whether the current XML is a separate XML. The default is yes to indicate that the current document does not need to be dependent on other documents, and if the current document is dependent on other documents, you need to set this value to No

2. Elements
An XML tag is an element
A label is divided into start and end tags
You can include text content between the start tag and the end tag, which is called the label body
If the label's start and end tags do not contain labels and sub-labels, you can merge the start and end tags so that the labels are called self-closing tags
You can also include any number of sub-labels in a label, but be aware that labels must be properly nested
A well-formed XML must contain and contain only one root tag, and the other labels should be the descendants of the tag.

Case sensitivity, such as,<p> and <p>, are two different tokens.
You cannot start with a number or punctuation mark or "_".
You cannot start with XML (or XML, or XML, and so on).
Cannot contain spaces
The middle of the name cannot contain a colon (:).


3. Properties
A label can have multiple properties, each with its own name and value, for example:
<china capital= "Beijing"/>
The name of the property is defined with the same naming convention as the XML element
The value of the property needs to be enclosed in single or double quotation marks.

4. Notes
<!--comment Content--
Annotations can appear anywhere in the XML document except at the very beginning of the entire document. Cannot appear before document declaration
Note Cannot nest annotations


5.CDATA Zone/Escape character
<! [cdata[escaped content]]>:
When a section of XML does not want to be parsed by the parser, it can be wrapped with CDATA zones
When the parser encounters a CDATA zone, its contents are treated as text and will not be parsed
Syntax: <! [Cdata[content]]>

Escape characters:
& &amp;
< &lt;
> &gt;
"-&quot;
'-&apos;

6. Processing instructions
Processing instructions, referred to as pi (processing instruction). The processing instruction is used to direct the parsing engine to parse the XML document content.
<?xml-stylesheet type= "Text/css" href= "1.css"?>



Second, DTD syntax---Understand the syntax, understand the DTD can be
1. How to introduce a DTD in XML
(1) External introduction
You can write the constraint content of the DTD in an external DTD file, which must be a. DTD and the file must be saved with UTF-8 encoding.
And then use it in the XML file.
<! DOCTYPE root element name the location of the SYSTEM file >
If the system is written to indicate that the currently introduced DTD is in the current file system, the later file location is the location on the current hard disk
<! DOCTYPE Document root node Public "DTD name" "DTD file URL" >
If the write is public, it indicates that the currently introduced DTD is in a common network location, after which the DTD name and the network location URL address of the DTD are indicated.
(2) Internal introduction
Writing DTDs directly in XML
<! DOCTYPE root element name [
DTD constraint ....
]>

2.DTD syntax
(1) Elements
<! Element element name constraint >
Element constraints:
Storage type: Any/empty
Element constraint: A list of child elements, enclosing the child elements that can be contained in parentheses
A comma can be used to split the child elements, indicating that the child elements must appear in order
A vertical bar can be used to split between child elements, and one of the surface child elements appears
#PCDATA indicates the inclusion of the label body

+ represents one or more times
* 0 or more times
? 0 or one time

You can also use parentheses for group operations


(2) Properties
<! attlist element name
Property Name Property Type property constraint
Property Name 2 Property Type property constraint
......
>

Property Type:
CDATA: The value representing the property is a normal string
Enumerated: The value of the property is a value in an enumerated list
ID: Indicates that the value of the property must be unique throughout the document, and if there is a duplicate ID, the checksum does not pass, the value of the ID attribute can only be started by letter, underscore, cannot use a number, cannot appear white space characters

Attribute constraints:
#REQUIRED---Indicates that the current property is an attribute that must exist, and if such a property does not exist, it will be error-proof at the time of validation
#IMPLIED---Indicates that the current property is an optional property that can or may not have
#FIXED ' fixed value '---indicates that the current property has a fixed value that does not need to be assigned, and automatically takes the fixed value as a value. If such a property specifies a value that is not a fixed value, the error is verified
The ' default '---indicates that the current property has a default value, and if another value is given, the default value is taken if no value is given


(3) Entity (entities)
<! A reference to a large piece of content can simplify the reuse of code

Referencing entities: Entities referenced in XML are referred to as reference entities
<! Entity entity name "Solid content" >
& Entity name;

Parameter entities: Entities referenced in the DTD are called parametric entities
<! Entities% entity name "Entity Content" >
% entity name;


Third, XML programming: Use Java program to delete and modify (CRUD) XML data

Analytic thought:
Dom parsing
Sax parsing
Based on these two analytical ideas, there are a lot of analytic APIs on the market.
Sun Jaxp has both Dom and sax, and this parsing API has been added to the J2SE specification, meaning that this parsing can be directly used without the need to import any third-party development packages. But this kind of parsing is inefficient, and no one uses it.
DOM4J can parse XML efficiently using the DOM approach.
Pull

!! dom4j
Import the development package, usually only need to import the core package can be, if you are using the process to prompt less what package to the Lib directory in the import of missing packages can be


IV. schema-XML constraint technology---need to master the concept of namespaces, will read a simple Schema can be, do not need to be written by everyone

Schema is an XML constraint technique that appears to replace the DTD
itself is also an XML, very convenient to use the XML parsing engine to parse
Very good support for namespaces
Supports more data types and supports user-defined data types
Can be defined at the semantic level, which is much more restrictive than DTD
Entities are not supported in relation to DTDs
Compared to the more complex DTD, the higher the cost of learning

How to introduce schema in XML---!!!!! The concept of namespaces: Unique names around the world, used to uniquely identify a resource, usually a company's domain name, but it doesn't really represent the location of the resource.


~ ~ ~ The syntax of the schema---refer to the documentation of the schema to understand

Notes from the Web

Getting Started with Javaweb 20160301---XML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.