Is there any other way to do like this job?
Yes, there are other,more appropriate, ways to do this job.
It's typically not a great idea to try to process RDF documents using XML tools, since the same RDF graph can often be represented a number of different ways in RDF/XML. This is discussed in more detail in my answer to How to access OWL documents using XPath in Java?, but we can see the issue pretty quickly here. After adding some additional namespace declarations your data looks like this:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:Situation="https://stackoverflow.com/q/22170071/1281433/"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Class/>
<owl:Class/>
<owl:ObjectProperty/>
<Situation:Situation rdf:about="http://localhost/rdf#situa0">
<Situation:composedBy></Situation:composedBy>
</Situation:Situation>
</rdf:RDF>
The same RDF graph can be serialized like this, too:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:Situation="https://stackoverflow.com/q/22170071/1281433/"
xmlns:owl="http://www.w3.org/2002/07/owl#" >
<rdf:Description rdf:nodeID="A0">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="http://localhost/rdf#situa0">
<rdf:type rdf:resource="https://stackoverflow.com/q/22170071/1281433/Situation"/>
<Situation:composedBy></Situation:composedBy>
</rdf:Description>
<rdf:Description rdf:nodeID="A1">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A2">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
</rdf:RDF>
If you're looking for a Situation:Situation
element, you'll find one in the first serialization, but not the second, even though they're the same RDF graph.
You could probably use a SPARQL query to get what you're looking for. The typical implementation of describe
queries might do what you want. E.g., the very simple query
describe <http://localhost/rdf#situa0>
produces this result (in RDF/XML):
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:Situation="https://stackoverflow.com/q/22170071/1281433/"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<Situation:Situation rdf:about="http://localhost/rdf#situa0">
<Situation:composedBy></Situation:composedBy>
</Situation:Situation>
</rdf:RDF>
Alternatively, you could ask for everything that has the type Situation:Situation
:
prefix s: <https://stackoverflow.com/q/22170071/1281433/>
describe ?situation where {
?situation a s:Situation .
}
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:s="https://stackoverflow.com/q/22170071/1281433/"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<s:Situation rdf:about="http://localhost/rdf#situa0">
<s:composedBy></s:composedBy>
</s:Situation>
</rdf:RDF>
The important point here is to use an appropriate query language for the type of data that you have. You have RDF, which is a graph-based data representation. An RDF graph is a set of triples. Your data is five triples:
_:BX2D6970b66dX3A1448f4e1bcfX3AX2D7ffe <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://localhost/rdf#situa0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://stackoverflow.com/q/22170071/1281433/Situation> .
<http://localhost/rdf#situa0> <https://stackoverflow.com/q/22170071/1281433/composedBy> "" .
_:BX2D6970b66dX3A1448f4e1bcfX3AX2D7ffd <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#ObjectProperty> .
_:BX2D6970b66dX3A1448f4e1bcfX3AX2D7fff <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
In the Turtle serialization, the graph is:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix Situation: <https://stackoverflow.com/q/22170071/1281433/> .
[ a owl:Class ] .
<http://localhost/rdf#situa0>
a Situation:Situation ;
Situation:composedBy "" .
[ a owl:Class ] .
[ a owl:ObjectProperty ] .
You should use SPARQL (the standard RDF query language) or an RDF-based API for extracting data from RDF documents.