Skip to content

Commit 594d522

Browse files
More precise XPath
1 parent 3982486 commit 594d522

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/de/rub/nds/modifiablevariable/util/XMLPrettyPrinter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.xml.xpath.XPathExpression;
2626
import javax.xml.xpath.XPathExpressionException;
2727
import javax.xml.xpath.XPathFactory;
28+
import javax.xml.xpath.XPathFactoryConfigurationException;
2829
import org.w3c.dom.Document;
2930
import org.w3c.dom.NodeList;
3031
import org.xml.sax.InputSource;
@@ -41,7 +42,8 @@ public class XMLPrettyPrinter {
4142
public static int IDENT_AMOUNT = 4;
4243

4344
public static String prettyPrintXML(String input) throws TransformerConfigurationException,
44-
ParserConfigurationException, SAXException, IOException, TransformerException, XPathExpressionException {
45+
ParserConfigurationException, SAXException, IOException, TransformerException, XPathExpressionException,
46+
XPathFactoryConfigurationException {
4547
Transformer transformer = TransformerFactory.newInstance().newTransformer();
4648
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
4749
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(IDENT_AMOUNT));
@@ -53,6 +55,10 @@ public static String prettyPrintXML(String input) throws TransformerConfiguratio
5355

5456
// XPath for selecting all text contents
5557
XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("//*[text()]/*");
58+
// this is better but it does not work, because the default java xpath
59+
// transformer does not support XPath 2.0
60+
// XPathExpression xpath =
61+
// XPathFactory.newInstance().newXPath().compile("//*[text()[matches(.,'^[0-9A-F ]*$')]]");
5662
// XPath for counting the number of ancestors of a current element
5763
XPathExpression xpathDepth = XPathFactory.newInstance().newXPath().compile("count(ancestor-or-self::*)");
5864

0 commit comments

Comments
 (0)