XML introductory tutorial-detailed introduction to entities

黄舟
Release: 2017-03-15 16:47:54
Original
1414 people have browsed it

Since the data is not in XML format, use the NDATA declaration to specify the data type . avi is a MIME media type defined in NOTATION. Embedding unparsed entities in XML is complicated and non-standard, so try not to use it. Entity

Use the ENTITY statement to define entities. For example:

<!ENTITY linux "linux is a very good system"> 用&linux;可引用该字符串
Copy after login

You can define an external entity and reference an external XML document

<!ENTITY linux SYSTEM "/home/linux/test.xml"> 使用&linux;可引用/home/linux/test.xml文档
Copy after login

External entities do not have XML declarations, but they can have text declarations. The two are very similar. The main difference is that the text declaration must have Encoding declaration, while version information is optional.

<?xml version="1.0" encoding="gb2312"?> 是一个合法的文本声明 <?xml encoding="gb2312"?> 也是一个合法的文本声明
Copy after login

Not all data is XML. Such as jpeg photos, mpeg movies, etc. XML recommends using external unparsed entities as a mechanism for embedding this content in documents. DTDSpecify a name and URI for entities containing non-XML data.

<!ENTITY movie SYSTEM "/home/linux/test.avi" NDATA avi>
Copy after login

Since the data is not in XML format, use the NDATA statement to specify the data type. avi is a MIME media type defined in NOTATION. Embedding unparsed entities in XML is complicated and non-standard, so try not to use it.

The parameter entity can define a set of common entities, and the entity can be referenced through the parameter entity in the document. The definition of parameter entities is similar to the definition of general entities, except that there is an extra % in the middle, and the % code & is also used when referencing.

<!ENTITY % person "name,address,postcode"> 引用方法 %person; 这样会用name,address,postcode代替参数实体%person;
Copy after login

Usually DTDs are relatively large. DocBook's DTD is more than 11,000 lines long. If it is stored in a single file, it will be very difficult to manage and maintain. We can use external DTD subsets to divide a large DTD into different functional blocks according to functions and store them in different files. Then introduce it into the current DTD through the external parameter entity declaration, such as:

Define the parameter entity to reference external names.dtd Call the external DTD subset %names;

Use the IGNORE keyword to comment the statement, such as:

<![IGNORE[ <!ELEMENT note (#PCDATA)> ]]>
Copy after login

Of course, the way of using is the same.

INCLUDEThe keyword indicates that the given statement is indeed used in the DTD, such as:

<![INCLUDE[ <!ELEMENT note (#PCDATA)> ]]>
Copy after login

Judging from this statement alone, the effect is the same whether or not INCLUDE is used. However, if INCLUDE and IGNORE are combined, DTD function selection can be achieved. We can define a parameter entity:

<!ENTITY % note_allowed "INCLUDE" >
Copy after login

Then use the parameter entity reference without using keywords:

<![%note_allowed;[ <!ELEMENT note (#PCDATA)> ]]>
Copy after login

According to the above operation, the element declaration is valid, but we can also put the parameter entity % note_allowed is redefined as IGNORE, so the element declaration is invalid.

The above is the detailed content of XML introductory tutorial-detailed introduction to entities. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!