File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Why these xpath function cannot work properly in such Document? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Why these xpath function cannot work properly in such Document?" Watch "Why these xpath function cannot work properly in such Document?" New topic
Author

Why these xpath function cannot work properly in such Document?

Shaohua Zhang
Greenhorn

Joined: Feb 15, 2004
Posts: 1
Why these xpath function cannot work properly in such Document?
I use String type as input parameter of a sessionbean function, 'cause i have to publish it as a web services.
A wield problem real bother me:
when i convert the String received to XmlDocument. some xpath functions cannot work properly.
Again, not all xpath, but some complex xpath expressions doesn't work!
e.g. when i use "//WfTransport/Dialog/ReplyToKey" to get key value, the function org.apache.xpath.XPathAPI.selectSingleNode return nothing. such thing like that.
I also find another intersting thing: when i apply these xpath functions to Xml Document which is created from xml file, Everything is perfect. I got what i want.
so, i guess some information of navigation in xml must be missing when converting a String to Xml Document.
but, How can i deal with this? Thanks a lot.
the following is my function to Convert String to Document. just like javaAlmanac:
附录A:

public org.w3c.dom.Document xmlString2Doc(String strXml) {
Document ret = null;
try {
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
// Create the builder and parse the file
ret = factory.newDocumentBuilder().parse(new InputSource(new
StringReader(strXml)));
}
catch (Exception e) {
e.printStackTrace();
}
return ret;
}
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Thinking out loud....
- try dumping the string strXml first.
- any namespace issues in your XPath ?
few things that I can think of....
- madhav


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why these xpath function cannot work properly in such Document?