要素を xml ドキュメントに追加して検索しようとしています。最近追加されたノードを検索すると、XPath が「null」を返しました。
ここに私の文書があります
<root>
</root>
それが私のコードです
File xmlFile = new File("C:\\caeycae.xml");
String uri = "http://www.w3.org/2000/svg";
DocumentBuilderFactory domFactory = DocumentBuilderFactory
.newInstance();
domFactory.setNamespaceAware(false);
DocumentBuilder builder;
builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
Element nodo = doc.createElementNS(uri, "e");
nodo.setAttributeNS(null, "id", "a");
doc.getDocumentElement().appendChild(nodo);
Element testElement = (Element) getNode("root/e[@id='a']", doc);
System.out.println("node:" + testElement);
System.out.println("xml:" + doc.getDocumentElement());
コンソール出力は次のとおりです。
node: null
xml: <root>
<e id="a"/>
</root>
ドキュメントが変更されたことを Xpath に通知する方法はありますか?