[英]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 / xml数据,我想获取元素
rtc_cm:Category
的值rtc_cm:Category
是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>
When working with RDF/XML data, I would not suggest using XPath to locate elements. 使用RDF / XML数据时,我不建议使用XPath来定位元素。 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.
RDF / XML不是普通的XML文件,实际结构可能因服务器端库确定的是在RDF / XML中表达内容的最佳方式而有所不同。 My suggestion would be to utilize a client side library for RDF/XML formats and leverage its API for finding elements (nodes).
我的建议是利用客户端库来获取RDF / XML格式,并利用其API来查找元素(节点)。 Namely using a library such as Apache Jena and using calls of the form:
即使用Apache Jena等库并使用以下形式的调用:
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 请注意,semanticweb.com上有一个类似的主题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.