Processing instructions

Processing instructions are represented by ProcessingInstruction nodes. The name of this type of node is the name of the target application (the first word in the tag). The value of this type of node is the instruction data that occupies the body of the tag.

The whitespace between the target and the instruction is implied, and parsers will insert a single space between them when writing out to XML format. The methods defined by this interface are:

String  getTarget();
String  getData();
void    setData(String data);

Consider the following example, which is referred to below. It consists of a target name of 'ACME' and an instruction of 'page-break':

<?ACME page-break ?>

Get target or data

The getTarget method returns the target application. From the example above, this method would return 'ACME':

String targetName = myPI.getTarget();

The getData method returns the processing instruction itself. From the example above, the method would return 'page-break':

// get 'page-break' or other instruction

String instruction = myPI.getData();

Set data

Although it is not possible to change the target name, it is possible to replace the instruction using the setData method:

// change 'page-break' to 'column-break'

try
{
  myPI.setData("column-break");
}
catch ( DOMException err ) { ... }

An exception is thrown if the node is read-only.

Creating PIs

The createProcessingInstruction factory method defined in the Document interface can be used to create new processing instruction nodes. It takes two parameters, the target name then the instruction:

// <?ACME page-break?>

ProcessingInstruction myProc =
   myDoc.createProcessingInstruction( "ACME",
                                      "page-break" );

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.150.89