0

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>
  • What have you tried to do this? Please add the XPath expressions you use. Please note that there are *two* `rtc_cm:Category` elements. Which one do you want? –  May 27 '13 at 07:43
  • Hi, i wants to fetch the rtc_cm:Category which should have rtc_cm:hierarchicalName =Test 2. My current xpath expression is : //rtc_cm:Category[rtc_cm:hierarchicalName=\""+Test 2+"\"]/@rdf:about but this is not working – Rahul Singh May 27 '13 at 07:55
  • WHy the +? Should be just `//rtc_cm:Category[rtc_cm:hierarchicalName="Test 2"]/@rdf:about`, assuming you want the value of the `about` attribute – dirkk May 27 '13 at 08:00
  • I an not even able to get the list of rtc_cm:Catagory attribute list I am using the following Xpath expression String wiXPath = "//rtc_cm:Category/@rdf:about"; – Rahul Singh May 27 '13 at 08:03
  • yes i am interested to get the value of the about attribute of the rtc_cm:Category element – Rahul Singh May 27 '13 at 08:04
  • Hi @dirkk, I have tried this one also: //rtc_cm:Category[rtc_cm:hierarchicalName="Test 2"]/@rdf:about but it's not working – Rahul Singh May 27 '13 at 08:08
  • 1
    @RahulSIngh Can you get *any* value from your xml? Your XPath looks fine to me and if you can't access anything thre might be another issue, maybe namspaces? Maybe try * as namespace wildcard for testing purposes and see if it works. – dirkk May 27 '13 at 08:30
  • 1
    Since you seem to be using Java, you probably have to setup a `NamespaceContext` first. See [this question](http://stackoverflow.com/questions/914013/namespacecontext-and-using-namespaces-with-xpath). – nwellnhof May 27 '13 at 12:31

1 Answers1

2

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

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
SteveS
  • 407
  • 2
  • 11