|
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. Are you sure @vipincpy meant XPath in RDF/XML documents and not XPath on actual RDF graphs? 1
Not really, but there is sometimes an expectation that arbitrary RDF/XML can be processed as XML; it need addition syntax constraints to be practical (there was an RDF/XML parser in XSLT ... to show it is possible only). As your first comment recognizes the question is not clear (it overlapped with my answer). That's unreadable. Please edit the original question and add, well formatted, the example. |
|
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. |
|
Hi there; Try to read rdf document with a tool.(jena is highly recommended). This link shows how to read RDF data. Then you can listStatements and filter results, or create a sparql query to get data. Good luck Çağdaş Cagdas, but how to get the xpath using apache-jena. my intention is not to paarse a rdf file. but to find the Xpath.Thanks in advance |


Please be more specific and describe what you have tried or think could work.
(The OP edited to add an example. I edited to clean up the text.)
XPath is a language for path specification in XML, so it's not clear to me what you mean with "I should get the XPath". Do you mean that you want an XPath expression that finds a particular element in this particular XML file (for your example the expression would be
/rdf:RDF/rdf:Description[cd:country='USA']/cd:country), or are you looking for something that can do XPath processing, or do you mean something else?jeen Broekstra. iam not trying to extract 'USA' from the xml file. what iam trying to extract is "/rdf:RDF/rdf:Description[cd:country='USA']/cd:country)" if i give "USA". Hope u r now clear with the query. my input will be USA and the output should be "/rdf:RDF/rdf:Description[cd:country='USA']/cd:country)"