DTD verification XML document, dtd verification xml

Source: Internet
Author: User
Tags cdata

DTD verification XML document, dtd verification xml

DTD verification XML document
1. DTD Introduction: DTD is short for Document Type Definition, that is, Document Definition.
1.1: The content of DTD includes:
Element Definition rules
Relationship rules between elements
Attribute definition rules
1.2: The Role of DTD is as follows:
DTD allows each XML file to carry a description in its own format
DTD allows people in different organizations to use a universal DTD to exchange data.
The DTD allows an application to use a standard DTD to verify whether XML data received from the outside is valid.
2. Declare a DTD
Syntax: <! DOCTYPE root element [definition content]>

Eg:

1 <? Xml version = "1.0"?> 2 <! DOCTYPE poem [3 <! ELEMENT poem (author, title, content)> 4 <! ELEMENT author (# PCDATA)> 5 <! ELEMENT title (# PCDATA)> 6 <! ELEMENT content (# PCDATA)> 7]> 8 <poem> 9 <author> Wang Wei </author> 10 <title> Lu Chai </title> 11 <content> no one is seen in kongshan, but the voice is heard. Back to the scene into the deep forest, re-photo Moss. </Content> 12 </poem>

 



3. Use external DTD to verify XML
Syntax: <! DOCTYPE root element SYSTEM "DTD file path">

Eg: poems. dtd

                        <!ELEMENT poems (poem*)>                        <!ELEMENT poem (title,author,year,content)>                        <!ELEMENT title (#PCDATA)>                        <!ELEMENT author (#PCDATA)>                        <!ELEMENT year (#PCDATA)>                        <!ELEMENT content (#PCDATA)>                

 



Use external DTD to verify the XML Description of poetry collections

1 <? Xml version = "1.0"?> 2 <! DOCTYPE poems SYSTEM "poems. dtd "> 3 <poems createYear =" 2011 "> 4 <poem> 5 <title> Chunxiao </title> 6 <author> Meng Haoran/author> 7 <year> 732 </ year> 8 <content> Xiaoxiao </content> 9 </poem> 10 </poems>

 



4. DTD Elements
4.1: Syntax: <! Element name content>
ELEMENT: keyword
NAME: element NAME
CONTENT: Element type
4.2: Common Element Types
# PCDATA, which can contain any character data, but cannot contain any child element
Eg: <! ELEMENT title (# PCDATA)>
Pure element type, only contains child elements, and these child elements do not have text
Eg: <! ELEMENT poems (poem *)>
4.3: usage of some symbols in a DTD Element
Symbol usage example
() Is used to group elements (Gu Long | Jin Yong | Liang Yusheng), (WANG Su | Yu Jie). Mao indicates that the Group is divided into three groups.
| Select one (man | woman) from the objects listed.
The object must appear in the specified Order (watermelon, apple, and banana ).
* Allowed to appear (0 to multiple times) (hobby *) Hobbies can appear 0 to multiple times
? Allowed to appear (0 to 1) (cainiao ?) It indicates that it can appear or does not appear. If it appears at most once
+ Allowed to appear (once to multiple times) (member +) indicates that it must appear and can appear multiple times
4.4: DTD attributes
1. Syntax: <! ATTLIST element name property type property default value>
2. Description of the attribute type in the DTD element:
Attribute type description
CDATA indicates character data
ID indicates a unique id.
IDREF indicates the id of another element.
IDREFS indicates the list of other IDS
ENTITY indicates an object
ENTITLES indicates an Object List
3. Description of the attribute values in the DTD Element
Value description
# The REQUIRED attribute value is REQUIRED.
# IMPLIED attribute values are not mandatory
# The FIXED property value is FIXED.
Eg:

 1                 <!DOCTYPE mystruts[ 2                                 <!ELEMENT mystruts (actions)> 3                                 <!ELEMENT actions (action*)>     4                                 <!ELEMENT action (result*)> 5                                 <!ATTLIST action     6                                         name CDATA #REQUIRED 7                                         class CDATA #REQUIRED> 8                                 <!ELEMENT result (#PCDATA)> 9                                 <!ATTLIST result10                                         name CDATA #IMPLIED11                                         redirect (true|false) "false">12                             ]>13                             <mystruts>14                                 <actions>15                                     <action name="register" class="com.RegisterAction">16                                         <result name="success">register_success.jsp</result>17                                         <result name="input">register.jsp</result>18                                     </action>19                                 </actions>20                             </mystruts>

 

Related Article

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.