Swapna Gupta wrote:
Hello,
Please help me solve my problem, which is thus:
I am constructing an XML DOM tree and saving it in Xindice as DOM tree, following is the code snippet for it:
DOMImplementation domImpl = new DOMImplementationImpl();
Document doc = domImpl.createDocument(null, "lesson", null);
Element root = doc.getDocumentElement();
root.setAttribute("xmlns", "http://swel.cs.ua.edu:8080/swapna/lessons");
root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.setAttribute("xsi:schemaLocation"," http://swel.cs.ua.edu:8080/swapna/lessons E:/SWEL-Shared/tomcat
server/webapps/useraccounts/swapna/lessons_learned_system/lessons_new.xsd" );
Element titleElement = doc.createElement("title");
Text titleText = doc.createTextNode(topic); /*topic contains a string*/
titleElement.appendChild(titleText);
root.appendChild(titleElement);
…..
…..
…
In the end, after constructing the complete DOM tree, I store it in Xindice as:
DatabaseManager.getCollection("xmldb:xindice://swel.cs.ua.edu:4080/db/" + colName); /*colName contains a String*/
XMLResource document = (XMLResource) col.createResource(null,
"XMLResource");
document.setContentAsDOM((Node)doc);
col.storeResource(document);
……
Now, I am trying to use XPath to make queries into these documents stored in Xindice. If I use a query like "/descendant::*", and output their result using getContent(), I can see all my documents. But, if I do a query like "/descendant::lesson" (lesson is the root element), the query finds no matches. On the other hand, if I store my documents by reading their contents as String from an XML file, I can query them using XPath correctly.
Are there any issues associated with using XPath for querying documents saved as DOM trees using setContentAsDOM() in Xindice?
I think the problem is that your xpath uses default namespace, while in the document you try to use "http://swel.cs.ua.edu:8080/swapna/lessons" namespace. At least that's how I interpreted your line:
root.setAttribute("xmlns", "http://swel.cs.ua.edu:8080/swapna/lessons");
but I think correct way to do it would be to pass it to createDocument:
Document doc = domImpl.createDocument("http://swel.cs.ua.edu:8080/swapna/lessons", "lesson", null);
Try this xpath: "/descendant::*:lesson", it should match any namespace.
Vadim
