Хотя ответ Димитра технически верен, несколько популярных библиотек теперь анализируют псевдоатрибуты инструкции обработки, как и следовало ожидать. Последующие примеры анализируют следующую инструкцию обработки XML, чтобы получить значение для псевдо-атрибута href
:
<?xml-stylesheet type="text/xsl" href="markdown.xsl"?>
JDOM2
Использование 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" ) );
}
}
Saxon
Использование 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" ) );
}
}