How can I extract an XPath for various nodes of an RDF document. Is it possible?
What I need is if I give the atomic value, I should get the XPath for it.
If I give '
Consider parsing the document and not using XPath. The same data (triples) can be written different ways in RDF/XML so any Xpath solution is not guaranteed to work on all data. Work at the data model level - SPARQL may help.
answered 25 Jan, 06:01
I gather from your clarification that you are looking for a way to generate an XPath expression given a string and an RDF/XML document as input, where the expression should match the XML node that contains the given string value.
First of all, this is not really a Semantic Web problem, but more a general XML processing problem (the fact that your XML document contains RDF seems immaterial).
Having said that, what you probably need to do is process your document using something like an XML DOM parser to find the matching node and then reconstruct the XPath expression from there. Alternatively, use an XPath processor to find a match using a very generic XPath expression (e.g. something like
In Java, you should be able to do this with any JAXP implementation, using
and then evaluate on your document to a DOM node to able to reconstruct the path, something like this (untested):
Once you have the DOM node, you should be able to reconstruct the path using
I'm not making any claims for efficiency or full correctness here, but this should get you started. For further help, I suggest you look up some tutorials on how to work with XML, DOM and XPath in Java, for example here is a good starting point.
answered 28 Jan, 17:47
Jeen Broekstra ♦