XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / ProcessingInstruction
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
This interface provides access to the contents of an XML processing instruction. Processing instructions are the preferred means of embedding instructions in XML documents for programs that process those documents.
Java example
// Ergänzen einer anwendungsspezifischen Verarbeitungsanweisung
ProcessingInstruction pi = doc.createProcessingInstruction("my_app",
"action=\"save\"");
Attributes
This interface has two attributes:
data: DOMString
Contains the data portion of the processing instruction. The data starts at the first non-whitespace character following target and ends at the closing ?>.
Exception
NO_MODIFICATION_ALLOWED_ERR
Raised when the node is read-only.
Java equivalents
public String getData( );
public void setData(String data) throws DOMException;
Java example
// Prüfe das data-Attribut der Anwendung.
if (pi.getTarget( ) == "MEINE_ANWENDUNG") {
// Prüfe das data-Attribut auf anwendungsspezifische Informationen,
// verarbeite die Anweisung.
if (pi.getData( ) == "ZÄHLE_GESCHWISTER") {
// Zähle die Geschwister.
...
}
pi.setData("GESCHWISTER_GEZAEHLT");
}
target: DOMString
Contains the target of the processing instruction, that is, the first word in the instruction terminated by whitespace.
Processing instructions pass hints about data processing to the application. These instructions are stored in the XML document itself. The target makes it possible to address instructions to different programs. Applications using processing instructions for document formatting should ignore instructions they do not recognize.
Java binding
public String getTarget( );
// Überprüfe, ob unsere Anwendung angesprochen ist.
if (pi.getTarget( ) == "MY_APPLICATION") {
// jetzt führen wir alle anwendungsspezifischen Verarbeitungsschritte durch.
}
Methods
ProcessingInstruction has no methods.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de