Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
239
The org.w3c.dom.ProcessingInstruction Interface
All Super interfaces: org.w3c.dom.Node
Members
Signature
Public methods
String
getData()
String
getTarget()
void
setData(String
data)
Overview
The ProcessingInstruction
interface represents a "processing instruction", used in XML as a way
to keep processor-specific information in the text of the document.
Example of handling ProcessingInstructions in SAX
Processing instructions within
XML are handled in a bit of special case as they are not considered XML
elements. SAX defines a specific call back method for handling PIs(Processing
Instructions). In a real application that is using XML data, this is where an
application should receive instructions and variable values or execute methods
to perform application-specific processing. E.g. the apache cocoon publishing
framework might set flags to perform transformation on the data once it is
parsed or to display the xml as a specific content type.
public void
processingInstruction(String target, String data){
System.out.println("PI: target: "+target+" and
Date :"+data);
}
Example of handling ProcessingInstructions in DOM
The
ProcessingInstruction node in the DOM is a little bit of a break from what you
have seen so far: to fit the syntax into the Node interface model, the
getNodeValue() method returns all data instructions within a
PI(ProcessingInstruction) in one String. This allows quick output of the PI. If
you were writing an application that received PIs from an XML document, you
might prefer to use the actual ProcessingInstruction interface; although it
exposes the same data, the method names( getTarget() and getData()) are more in
line with a PI’s format. With this understanding, you can add in the code to
print out any Pis in supplied document: