First, how do I format the XML processing instruction, is it:
Usi
Although Dimitre's answer is technically correct, a few popular libraries now parse processing instruction pseudo-attributes as would be expected. The subsequent examples parse the following XML processing instruction to obtain the value for the href
pseduo-attribute:
Using JDOM2:
import org.jdom2.ProcessingInstruction;
import org.xml.sax.helpers.DefaultHandler;
public class ProcessingInstructionHandler extends DefaultHandler {
@Override
public void processingInstruction( final String target, final String data ) {
final ProcessingInstruction pi = new ProcessingInstruction( target, data );
System.out.println( pi.getPseudoAttributeValue( "href" ) );
}
}
Using Saxon:
import static net.sf.saxon.tree.util.ProcInstParser.getPseudoAttribute;
import org.xml.sax.helpers.DefaultHandler;
public class ProcessingInstructionHandler extends DefaultHandler {
@Override
public void processingInstruction( final String target, final String data ) {
System.out.println( getPseudoAttribute( data, "href" ) );
}
}