This is easy (or as easy as it can be, given the design of XPath and XML Namespaces). You just need to add any namespaces you want to use to the context manually. For instance, in this case,
XPathContext xc = new XPathContext();
xc.addNamespace("ns4", "http://sample.xml.com/ns4");
xc.addNamespace("ns1", "http://sample.xml.com/ns1");
doc.query("ns4:parent/ns4:child1/ns1:child2", xc);
Note that you do not have to use the same prefixes in the XPath expression that the document uses.