- DTD - Validation
- DTD - Entities
- DTD - Attributes
- DTD - Elements
- DTD - Components
- DTD - Syntax
- DTD - Overview
- DTD - Home
DTD Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
DTD - Entities
各实体在XML文件中用来界定特殊性质的捷径。 实体主要可以分为四类:
Built-in实体
特征实体
一般实体
参数实体
Entity Declaration Syntax
一般来说,实体可申报> > /internally或externally。 让我们理解其中的每一条及其各条:
Internal Entity
如果一个实体在TDD中被宣布为内部实体。
Syntax
以下是内部实体申报的辛迪加——
<!ENTITY entity_name "entity_value">
以上各条:
entity_name/b> is the name of entities follow by its Value within the Double quotes or one quote.
内部实体的实体价值通过在实体名称上添加序号和amp;;在实体名称上添加“i.e. &entity_name.。
以下是内部实体申报的简单例子:
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <!DOCTYPE address [ <!ELEMENT address (#PCDATA)> <!ENTITY name "Tanmay patil"> <!ENTITY company "TutorialsPoint"> <!ENTITY phone_no "(011) 123-4567"> ]> <address> &name; &company; &phone_no; </address>
在上述例子中,各实体的名称, 姓名,company和phone_no在XML文件中被其价值所取代。 实体的数值通过在实体名称上添加标题和amp;。
Save this file as sample.xml 并开放给任何浏览器,您将注意到,实体的数值为 :,company, phone_no被分别取代。
External Entity
如果一个实体在TDD之外申报,则称为外部实体。 可以通过使用系统识别器或公共识别器来指外部实体。
Syntax
以下是对外实体宣言的辛迪加——
<!ENTITY name SYSTEM "URI/URL">
以上各条:
<>名称为实体名称。
SYSTEM是关键词。
URI/URL是双重或单一报价内外部来源的地址。
您可以通过以下两种方式提及外部的DVD:
System Identifiers——系统识别资料使你能够具体说明载有TD声明的外部档案的位置。
你们可以看到,它含有关键词“海关数据”和“世界投资报告”的参考资料,指出该文件的位置。 综合症如下:
<!DOCTYPE name SYSTEM "address.dtd" [...]>
Pubpc Identifiers -Pubpc ID provide a mechanism to identifying DTD resources and are written as below -
如你所知,它首先从共和国的关键词开始,然后是专门标识。 公共识别器用于识别输入数据。 公共识别器可采用任何格式;然而,通常使用的格式称为Formal Pubpc Identifiers,或FPIs。
<!DOCTYPE name PUBLIC "-//Beginning XML//DTD Address Example//EN">
让我们以以下榜样理解外部实体:
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <!DOCTYPE address SYSTEM "address.dtd"> <address> <name> Tanmay Patil </name> <company> TutorialsPoint </company> <phone> (011) 123-4567 </phone> </address>
以下是DTD文档的内容:address.dtd。
<!ELEMENT address (name, company, phone)> <!ELEMENT name (#PCDATA)> <!ELEMENT company (#PCDATA)> <!ELEMENT phone (#PCDATA)>
Built-in实体
所有XML教区都必须支持已建实体。 总的来说,你可以在任何地方使用这些实体的参考资料。 您也可在《国际洗钱法》文件中使用正常文本,如内容和属性价值。
有五个内在实体在知情的XML中发挥作用,它们是:
邮局: &
单一报价:和
大于:
少于:及
双重引用:和;引用;
Example
下面举例说明了内在实体申报——
<?xml version = "1.0"?> <note> <description>I m a technical writer & programmer</description> <note>
如你可以在这里看到,“安乐”一词;特性被“安乐”所取代;只要加工商会这样做。
特征实体
特征实体用来指代表信息的某些实体,即难以或不可能分类的特性,可由特性实体替代。
Example
下面举例说明实体申报的性质:
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <!DOCTYPE author[ <!ELEMENT author (#PCDATA)> <!ENTITY writer "Tanmay patil"> <!ENTITY copyright "©"> ]> <author>&writer;©right;</author>
您将在此通知我们已使用©作为版权价值。 将这一档案作为sample.xml予以保存,并在您的浏览器上开放,你将看到版权由 character取代。
一般实体
一般实体 must be declared within the DTD before they can be used within an XML document. Instead of representing only a single character, general entities can represent characters, paragraphs, and even entire documents.
Syntax
1. 宣布一个普通实体,使用本一般形式的声明。
<!ENTITY ename "text">
Example
举例来说,一般实体声明——
<?xml version = "1.0"?> <!DOCTYPE note [ <!ENTITY source-text "tutorialspoint"> ]> <note> &source-text; </note>
每当XML教区提到源-text的实体时,它将在参考点提供替代案文。
参数实体
参数实体的目的是使你能够创建替代案文中可重新使用的部分。
Syntax
参数实体申报表如下:
<!ENTITY % ename "entity_value">
Example
以下举例说明了参数实体的申报。 附录
<!ELEMENT residence (name, street, pincode, city, phone)> <!ELEMENT apartment (name, street, pincode, city, phone)> <!ELEMENT office (name, street, pincode, city, phone)> <!ELEMENT shop (name, street, pincode, city, phone)>
现在,你想增加一句:country,然后,你需要在所有四项宣言中加入。 因此,我们可以找到参数实体参考。 如今使用参数实体参考,即:
<!ENTITY % area "name, street, pincode, city"> <!ENTITY % contact "phone">
参数实体 are dereferenced in the same way as a general entity reference, only with a percent sign instead of an ampersand −
<!ELEMENT residence (%area;, %contact;)> <!ELEMENT apartment (%area;, %contact;)> <!ELEMENT office (%area;, %contact;)> <!ELEMENT shop (%area;, %contact;)>
当主人读这些声明时,代之以实体的替换案文作为实体参考。
Advertisements