package xpathCheck; import org.dom4j.Document; import org.dom4j.io.SAXReader; public class XPathCheck { public static void main(String[] args) { boolean xmlMissingTagYieldsNullValue = true; // KETTLE_XML_MISSING_TAG_YIELDS_NULL_VALUE=Y を模す String filePath = "D:\\pleiades\\sampledata\\Sample.xml"; String xpathExpression = "count(/root/employees/employee)"; SAXReader rdr = new SAXReader() ; String nodeValue; try { Document doc = rdr.read(filePath); // 暫定的な修正例 nodeValue = doc.valueOf(xpathExpression); if((xmlMissingTagYieldsNullValue)&&(nodeValue.length() == 0)) nodeValue = null; System.out.println("XPath: " + xpathExpression); System.out.println("Node Value: " + nodeValue); } catch (Exception e) { e.printStackTrace(); } } }