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.

  

 

 

 

back to top