I am trying to find XML node's which has an attributed called "CommunityOwnedDate" in an XML node in java. I am using jdom2. Some node doesn't have that node and i am trying to find that using jdom2. Is there any other straightforward way to do this?
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;
String xml = "<row Id="4" PostTypeId="1" AcceptedAnswerId="7" CreationDate="2008-07-31T21:42:52.667" Score="322" ViewCount="21888" AnswerCount="13" CommentCount="1" FavoriteCount="27" CommunityOwnedDate="2012-10-31T16:42:47.213" />"
SAXBuilder saxBuilder = new SAXBuilder();
Document doc = saxBuilder.build(new StringReader(xml))
Element row = doc.getRootElement();
XPathFactory xpfac = XPathFactory.instance();
XPathExpression xp = xpfac.compile("//row[@CommunityOwnedDate]");
var xpathObjects= xp.evaluate(doc);
And then i want to check it like this:
if(xpathObjects != null){
//do something
}
consequently, it throws this exception: java.lang.ClassNotFoundException: org.jaxen.NamespaceContext at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)