I have not been able to query RDF document using XPath since it does not work with RDF namespace, although RDF is basically an XML document. SPARQL is used for querying RDF document. What is difference between XPath and SPARQL?
RDF documents are named directed graphs: an RDF document is a set of subject,predicate,object statements that you can think of as a set of graph edges, where edges are named after the predicate and run from the subject to the object.
RDF/XML is a way to serialize RDF so that it can be stored or transferred, and it is not the only possible serialization for RDF. TTL, for instance, can be used instead of RDF/XML.
If your RDF data happens to be serialized as RDF/XML, it is possible to use XPath to query it, although it's not very advisable. If you use XPath you will spend too much effort and energy worrying about the syntax of the serialization instead of worrying about what it is you want to retrieve from the document.
SPARQL is a SQL-like language that is a much more intuitive way to query RDF documents, regardless of how they are stored. With SPARQL you will query the data using patterns over the edges of the graph, so that getting the names of X's grandchildren will be as straightforward as
?X ex:child ?Y .
?Y ex:child ?Z .
?Z foaf:name ?Name .
Now about your specific problem, and if you haven't been persuaded yet to use SPARQL instead of XPath, you should post the minimal data and the query needed to reproduce the problem, so people can help.
In addition to the answer above, I'll add that RDF can be serialized into RDF/XML in different ways and your XPath expressions may not account for all the different variants of the syntax - unless you have a good control of how RDF is produced and serialized. I would strongly advice against using XPath and suggest SPARQL instead. Look at open source frameworks like Apache Jena or Eclipse RDF4J - they probably provide the functionality you need.