createProcessingInstruction (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM1 | No | No |
| IE5.5+ | FF1.5+ | SA3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Buggy |
- Returns
ProcessingInstruction- Throws
INVALID_CHARACTER_ERR,NOT_SUPPORTED_ERR
Example
var pi = document.createProcessingInstruction
('xml-stylesheet', 'type="text/xml" href="test.xsl"');
The
example above creates a ProcessingInstruction node,
with the target
xml-stylesheet and the data type="text/xml"
href="test.xsl".
The end result of that operation would be this XML:
<?xml-stylesheet type="text/xml" href="test.xsl"?>
You'll
notice how there's a space between the name and the data, which is
required to separate them in static XML; and indeed, when we retrieve the
data property of a static
ProcessingInstruction node, that leading space is
included. However it's not necessary to include it in the data argument of this method.
Arguments
Description
Create a ProcessingInstruction node in an XML document, with the
specified target and data.
The created node can
then be added to the document using Node methods
such as appendChild or insertBefore.
The XML Prolog at the top of an XML document is not a processing instruction, even though it looks like one.
Return value
The created processing instruction node.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| Full | Full | Full | Full | Full | Full | Buggy | Buggy | Full | Buggy | Buggy |
The specification
says that this method should throw a DOMException
in HTML mode1 (code 9: NOT_SUPPORTED_ERR).
Therefore if a browser supports it and does not throw an exception in that
mode, this is considered a bug, and is what happens in
Opera and Safari 1.3 and
2.
In Internet Explorer in HTML this method
is not implemented (it returns undefined). Similarly to the previous
note, this cannot be considered a bug or lack of support because ProcessingInstruction is an XML construct.
Footnotes
1 On XHTML or HTML pages served as
text/html.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.