Xml 简明教程

XML - Processing

本章节介绍 Processing Instructions (PIs) 。按照 XML 1.0 建议书的定义,

This chapter describes the Processing Instructions (PIs). As defined by the XML 1.0 Recommendation,

处理指令 (PI) 可用于向应用程序传递信息。PI 可以出现在标记之外的文档中的任何位置。它们可以出现在前言中,包括文档类型定义 (DTD)、文本内容中或文档之后。

Processing instructions (PIs) can be used to pass information to applications. PIs can appear anywhere in the document outside the markup. They can appear in the prolog, including the document type definition (DTD), in textual content, or after the document.

Syntax

以下是 PI 的语法 −

Following is the syntax of PI −

<?target instructions?>

其中

Where

  1. target − Identifies the application to which the instruction is directed.

  2. instruction − A character that describes the information for the application to process.

PI 以特殊标记 <? 开头,以 ?> 结尾。在遇到字符串 ?> 后,内容的处理将立即结束。

A PI starts with a special tag <? and ends with ?>. Processing of the contents ends immediately after the string ?> is encountered.

Example

很少使用 PI。它们主要用于将 XML 文档与样式表链接。以下是示例 −

PIs are rarely used. They are mostly used to link XML document to a style sheet. Following is an example −

<?xml-stylesheet href = "tutorialspointstyle.css" type = "text/css"?>

此处,目标是 xml-stylesheet。href="tutorialspointstyle.css" 和 type="text/css" 是目标应用程序在处理给定 XML 文档时将要使用的数据或指令。

Here, the target is xml-stylesheet. href="tutorialspointstyle.css" and type="text/css" are data or instructions the target application will use at the time of processing the given XML document.

在这种情况下,浏览器通过指示在显示 XML 之前对其进行转换来识别目标;第一属性说明转换类型为 XSL,第二属性指向其位置。

In this case, a browser recognizes the target by indicating that the XML should be transformed before being shown; the first attribute states that the type of the transform is XSL and the second attribute points to its location.

Processing Instructions Rules

PI 可包含除 ?> 组合(解释为结束分隔符)之外的任何数据。以下是两个有效的 PI 示例 −

A PI can contain any data except the combination ?>, which is interpreted as the closing delimiter. Here are two examples of valid PIs −

<?welcome to pg = 10 of tutorials point?>

<?welcome?>