Home >Backend Development >XML/RSS Tutorial >XML introductory tutorial-detailed introduction to entities

XML introductory tutorial-detailed introduction to entities

黄舟
黄舟Original
2017-03-15 16:47:541457browse

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;可引用该字符串

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

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

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"?> 也是一个合法的文本声明

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>

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;

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 306ed4bb2d5e139f07d01a620bc7cca5 Call the external DTD subset %names;

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

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

Of course, the way of using e05c4b47b13fdc91df7336c657836442 is the same.

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

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

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" >

Then use the parameter entity reference without using keywords:

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

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!

Statement:
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