I am trying to extract information from a XML file and able to extract values without its properties.
Code:
public class NRusEntity {
private String code;
private String name;
private String saltForm;
getters and setters
...
Parser Class:
...
String filePath = FileUtility.getOwlFilePath();
try {
Digester digester = new Digester();
digester.setValidating(false);
//digester.setNamespaceAware(true);
digester.addObjectCreate("rdf:RDF", NRus.class);
digester.addObjectCreate("rdf:RDF/owl:Class", NRusEntity.class);
digester.addCallMethod("rdf:RDF/owl:Class/Preferred_Name", "setName", 0);
digester.addCallMethod("rdf:RDF/owl:Class/code", "setCode", 0);
/**This commented part creates exception*/
//digester.addCallMethod("rdf:RDF/owl:Class/Has_Salt_Form", "setSaltForm", 2);
//digester.addCallParam("rdf:RDF/owl:Class/Has_Salt_Form", 0);
//digester.addCallParam("rdf:RDF/owl:Class/Has_Salt_Form", 1, "rdf:resource");
digester.addSetNext("rdf:RDF/owl:Class", "addEntry");
File input = new File(filePath);
digester.parse(input);
}
...
XML Looks like this:
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Class rdf:about="#z">
<Preferred_Name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">von</Preferred_Name>
<code rdf:datatype="http://www.w3.org/2001/XMLSchema#string">XY221</code>
<Has_Format rdf:resource="http://zlib.com#Ni_Hydro"/>
</owl:Class>
...
</rdf:RDF>
How can I extract the URI value
"http://zlib.com#Ni_Hydro"
from that XML line
<Has_Format rdf:resource="http://zlib.com#Ni_Hydro"/>
I can't tell exactly as your XML does not appear to quite match your code: the commented out code refers to a
Has_Salt_Formelement but therdf:resourceelement appears on aHas_Formatelement. However, I can see one potential problem which may help you progress:I'm assuming your
NRusEntityclass setter is something like:However, the digester code you have is:
This is looking for a
setSaltFormmethod with two parameters (the first is the element body, the second therdf:resourceattribute), so will not match the simple setter, and you'll get something like "no such method" in the exception message.So if you need the body content then try adding another set method:
Or if you don't need the content then drop it from the digester rules:
If neither of those work can you add details of the version of digester you are using, and the exception you get.