// Postive test for XPath on ODF attributes
String resTest1 = xpath.evaluate("//text:p[@text:style-name='Standard']", contentDom);
Assert.assertTrue(resTest1 != null);
// Test XPath on none ODF attributes (added explicitly via DOM)
OdfTextParagraph p = doc.newParagraph();
p.setAttributeNS("http://myAttributeNamespace", "my:attr", "attrValue");
String resAttr1 = xpath.evaluate("//*[@my:attr = 'attrValue']", contentDom);
Assert.assertTrue(resAttr1 != null);
// Test XPath on none ODF element (added explicitly via DOM)
p.appendChild(contentDom.createElementNS("http://myElementNamespace", "my:element"));
String resElement1 = xpath.evaluate("//my:element", contentDom);
Assert.assertTrue(resElement1 != null);
// Save documnet
File targetFile = ResourceUtilities.newTestOutputFile(TARGET);
doc.save(targetFile);
// Load document with ODF foreign attriute
OdfTextDocument docReloaded = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath(TARGET));
OdfFileDom contentDomReloaded = docReloaded.getContentDom();
// Postive test for XPath on ODF attributes
xpath = contentDomReloaded.getXPath();
String resTest2 = xpath.evaluate("//text:p[@text:style-name='Standard']", contentDomReloaded);
Assert.assertTrue(resTest2 != null);
// Test XPath on none ODF attributes (added via load)
String resAttr2 = xpath.evaluate("//*[@my:attr = 'attrValue']", contentDomReloaded);
Assert.assertTrue(resAttr2 != null);
// Test XPath on none ODF element (added via load)
p.appendChild(contentDom.createElementNS("http://myElementNamespace", "my:element"));
String resElement2 = xpath.evaluate("//my:element", contentDomReloaded);
Assert.assertTrue(resElement2 != null);
} catch (Exception ex) {
Logger.getLogger(NamespaceTest.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);