XML (2)

Source: Internet
Author: User
Tags xml parser

 

XML document structure

<? XML version = "1.0" [1.0] encoding = "UTF-8" [encoding set] standalone = "yes" [is an independent XML document?]>

<! Doctype root tag name system "dtd1.dtd"> reference of DTD

<Root tag>

<Sub-tag> </sub-tag>

.......

</Root tag>

 

Dtd1.dtd to define the elements that can appear in the XML document, the attributes of the elements, and the order of the elements

<! XML version = "1.0" encoding = "UTF-8"?>

<! Element element name element type> ------- define Element

<! ATTLIST element name attribute type keyword [optional or optional] "Default Value"> -------- define attributes of an element

<! Element BR empty> --- BR cannot have content. It can be <br/> single mark or <br> </BR> NO content

<! Element element name (# pcdata)> ------- the content of the element defined by pcdata is text and cannot contain sub-tags.

<! Element student (student ID, name)> -------- only the student ID and name can appear in the student

<! Element student (# pcdata | student ID | Name) *> -------- the name and student ID can appear unordered multiple times. If not, * is mutually exclusive.

 

Define mixed content elements

<! Element parent element name (# pcdata | child element 1 | child element 2 | child element 3 .....) *>

<? XML version = "1.0" encoding = "gb2312"?>

<! Element favorite games (# pcdata | games) *>

<! Element game (# pcdata | game name | game type) *>

<! Element game name (# pcdata)>

<! Element game type (# pcdata)>

<! XML version = "1.0" encoding = "UTF-8"?>

<Favorite games>

This is my favorite game

<Game>

<Game name>

This is the name of the game. The name and type can be swapped and can appear multiple times.

</Game Name>

<Game type>

This is a game type

</Game type>

 

</Game>

</Favorite games>

 

<Book list>

<Computer books>

<Title> complete </title>

</Computer books>

<Computer books>

<Price> </price>

</Computer books>

 

</Book list>

 

ATTLIST element name attribute name type keyword "Default Value" attribute name type keyword "Default Value"...>

 

# Required this attribute is required

# Implied this attribute can have no

# Fixed this property has a fixed value, whether set or not, it is a fixed value

Eg:

<! Element author address CDATA # fixed "baoding city">

<! ATTLIST author gender (male | female) "male"> --------- Enumeration type, default: male, can only be selected between male and female

<! Element reader empty>

<! ATTLIST reader's book number idref # implied> -------- the Book Number read by the reader

<! ATTLIST reader account idrefs # implied> ------------- you can write the number of multiple books in XML.

<Reader's book number = "it0001 it0002">

Logical relationship between child elements:

1. Ordered sub-elements

Use commas (,) as the separator between child elements, then the child

Elements must follow the defined sequence.

2. Mutually Exclusive child elements

Mutually Exclusive child elements indicate that a series of child elements can only appear

Once. The mutex child elements are separated by vertical bars (| ).

Multiple Elements separated by a line (|) can only appear in one of them.

 

3. unordered child elements

<! Element student (# pcdata | student ID | Name) *> -------- the name and student ID can appear unordered multiple times. If not, * is mutually exclusive.

 

Occurrence frequency of child elements:

+: Indicates that the child element can appear once or multiple times.

*: Indicates that the child element can appear 0 or multiple times.

? : Indicates that the child element can appear 0 or 1 time

 

Define any type of Elements

<! Element element name any>

Elements defining string content

<! Element # pcdata>

 

Define attribute type

Attribute type

Description

CDATA

String data

(EN1 | EN2 | ..)

This value is a value in the enumeration list.

ID

The property value must be a valid identifier, which is unique in the XML document.

Idref

The value is the ID attribute value of another element.

Idrefs

Values must be referenced from multiple existing ID attribute values. Multiple ID attribute values are separated by spaces.

Nmtoken

The value is a valid XML name.

Nmtokens

List of multiple valid XML names

Entity

The value is an external entity, which is supported by slices.

Entities

A value is a list of entities separated by spaces.

Notation

This attribute value is a token that has been declared in the DTD. It is expired. Do not use it.

 

 

Define object functions

1. Improve the application of code to facilitate modification and maintain XML documents

2. Some special symbols may confuse the XML parser.

3. Reduce Character Input. If a character string is particularly long and needs to be used frequently, it can be defined as an object.

 

Content "detailed content Introduction"

& Content; ------ entity reference, equivalent to the string "detailed content Introduction"

 

Entity Classification

1. classify objects according to their specific content,Objects can be divided into two types: resolvable and non-resolvable..

2. objects are classified by logical storage.Internal entities and external entities

3. objects are classified by scope of use.Common entities and parameter entities.

 

Define common entities

<! Entity entity name "entity value"> ------ internal entity, common entity

<! Entity title "list of all computer books">

Use entity Syntax:

& Entity name;

& Title;

Define parameter entities

<! Entity % entity name "entity value">

Use entity Syntax:

% Entity name

External normal entity

<! Entity entity name system "object Value URI of the object">

<! Entity entity name public "public entity identification name" "object Value URI">

External parameter entity

<! Entity % entity name system | public ["public entity identification name"] "entity value file URI">

 

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.