• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why these xpath function cannot work properly in such Document?

 
Shaohua Zhang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking out loud....
- try dumping the string strXml first.
- any namespace issues in your XPath ?
few things that I can think of....
- madhav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic