Document.createProcessingInstruction() - Web APIs 编辑

createProcessingInstruction() generates a new processing instruction node and returns it.

The new node usually will be inserted into an XML document in order to accomplish anything with it, such as with node.insertBefore.

Syntax

piNode = document.createProcessingInstruction(target, data)

Parameters

  • piNode is the resulting ProcessingInstruction node.
  • target is a string containing the first part of the processing instruction (i.e., <?target … ?>)
  • data is a string containing any information the processing instruction should carry, after the target. The data is up to you, but it can't contain ?>, since that closes the processing instruction.

Exceptions

DOM_INVALID_CHARACTER
Throws if either of the following are true:
  • The processing instruction target is invalid — it should be a valid XML name that doesn't contain "xml", "XML", or any case combination of the two, other than standardized ones such as <?xml-stylesheet ?>.
  • The closing processing instruction sequence (?>) is part of the data.

Example

var doc = new DOMParser().parseFromString('<foo />', 'application/xml');
var pi = doc.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"');

doc.insertBefore(pi, doc.firstChild);

console.log(new XMLSerializer().serializeToString(doc));
// Displays: <?xml-stylesheet href="mycss.css" type="text/css"?><foo/>

Specifications

SpecificationStatusComment
DOM
The definition of 'createProcessingInstruction()' in that specification.
Living StandardNo change
DOM4
The definition of 'createProcessingInstruction()' in that specification.
ObsoleteAdded more explicit definition of how the data parameter is validated.
Document Object Model (DOM) Level 3 Core Specification
The definition of 'createProcessingInstruction()' in that specification.
ObsoleteAdded note that the namespace of the target name is not checked whether it is well-formed, defined what is considered an illegal character for the target name and specified the returned ProcessingInstruction object more precisely.
Document Object Model (DOM) Level 2 Core Specification
The definition of 'createProcessingInstruction()' in that specification.
ObsoleteNo change
Document Object Model (DOM) Level 1 Specification
The definition of 'createProcessingInstruction()' in that specification.
ObsoleteInitial definition

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:107 次

字数:4985

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文