Rahul Singh
Rahul Singh

Reputation: 3

Retrieving element data using xpath from a xml/rdf documents

I have following rdf/xml data and i want to fetch the value of the element rtc_cm:Category which is https://test.yahoo.com:9443/ccm/resource/itemOid/com.Category/_ivX6csaREeK41JJsvCkJ_A

<rdf:RDF>
  <rdf:Description rdf:about="https://server:9443/ccm/oslc/categories">
    <rdfs:member>
      <rtc_cm:Category rdf:about="https://server:9443/ccm/resource/itemOid/com.Category/_ivX6csaREeK41JJsvCkJ_A">
        <rtc_cm:hierarchicalName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Test 2</rtc_cm:hierarchicalName>
      </rtc_cm:Category>
    </rdfs:member>
    <rdfs:member>
      <rtc_cm:Category rdf:about="https://server:9443/ccm/resource/itemOid/com.Category/_iV5DcMaREeK41JJsvCkJ_A">
        <rtc_cm:hierarchicalName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Unassigned</rtc_cm:hierarchicalName>
      </rtc_cm:Category>
    </rdfs:member>
  </rdf:Description>
  <oslc:ResponseInfo rdf:about="https://server:9443/ccm/oslc/categories?oslc.select=rtc_cm:hierarchicalName&oslc.where=rtc_cm:projectArea=%22_fE-FT8aREeK41JJsvCkJ_A%22">
    <dcterms:title>Categories</dcterms:title>
    <oslc:totalCount>2</oslc:totalCount>
  </oslc:ResponseInfo>
</rdf:RDF>

Upvotes: 0

Views: 1094

Answers (1)

SteveS
SteveS

Reputation: 407

When working with RDF/XML data, I would not suggest using XPath to locate elements. RDF/XML is not your normal XML file, the actual structure may vary based on what the server-side library determines is the optimal way to express the content in RDF/XML. My suggestion would be to utilize a client side library for RDF/XML formats and leverage its API for finding elements (nodes). Namely using a library such as Apache Jena and using calls of the form:

Property rdfTypeProp = model.getProperty(
  "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
Resource categoryNode = model.getResource(
  "https://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/Category");
StmtIterator categoryIterator = model.listStatements(
  new SimpleSelector(null, rdfTypeProp , categoryNode));

Note there is a similar thread on semanticweb.com

Upvotes: 2

Related Questions