ルート ノード用に宣言されたデフォルトの名前空間を持つ XML ファイルで XPath を使用しようとしています。
コード例:
final SAXBuilder builder = new SAXBuilder();
final Document document = builder.build(originalFile);
final XPathFactory xFactory = XPathFactory.instance();
final String expression = String.format("//section[@label='%s']/section/section", LABEL);
final XPathExpression<Element> sectionExpression = xFactory.compile(expression, Filters.element());
final List<Element> sections = sectionExpression.evaluate(document);
セクションが空です。
XML のスニペット
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://www.stellent.com/sitestudio/Project/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.stellent.com/sitestudio/Project/ http://www.stellent.com/sitestudio/ss_project_schema.xsd">
<section label="Index">
<section label="xyz">
<section label="child">
...
</section>
</section>
</section>
</project>
作品を削除しxmlns="http://www.stellent.com/sitestudio/Project/"
ますが、解決策ではありません!
XPath がこの既定の名前空間を認識できないのはなぜですか? また、なぜ気にするのですか?
さらに良いことに、これを一般的に修正するにはどうすればよいですか?
洞察をありがとう。