aspose file tools*
The moose likes XML and Related Technologies and the fly likes MbElement.evaluateXPath(String) - what am I doing wrong with it. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "MbElement.evaluateXPath(String) - what am I doing wrong with it." Watch "MbElement.evaluateXPath(String) - what am I doing wrong with it." New topic
Author

MbElement.evaluateXPath(String) - what am I doing wrong with it.

Joe Vahabzadeh
Ranch Hand

Joined: Jan 05, 2005
Posts: 140
Alright, so let's say I have the following XML fragment as part of a SOAP message:


Now, I have the following code:


The inputBody is in effect the MbElement representing the SOAP node.

Now, I can do the following:


and I will wind up with firstDetail being an MbElement that represents the first DETAILS element - whose value is "M5-100"

However, if I do this:


I would EXPECT that details is a List<MbElement> with a size of 3, with each one being a DETAILS element. However, it comes back as an empty list.


Oddly, I CAN do this:

and it will work - I get a List<MbElement> of size 1, and that one item is the Body MbElement. But any deeper in the hierarchy, and it just gives me an empty list.

So, why is that? What am I doing wrong that I am not getting a 3-element List<MbElement> back?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 513
    
    3
You have to make sure BASE, ORDER, DETAILS all of them are not in any namespace, ie, they are all in null namespace. Since you say SOAP node, SOAP message etc etc, it seems unlikely that they are.

Here is a simple test. Use this line instead for a quick test.

If that returns a list of size 3, you then identify their namespace and use the MbXPath to set the xpath up properly with prefix(es) corresponding to their namespace(s).
Joe Vahabzadeh
Ranch Hand

Joined: Jan 05, 2005
Posts: 140
Thank you again for your help - I had "almost" discovered that same issue - that it was a namespace problem, but was still working it out.... going to change my code now to account for this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MbElement.evaluateXPath(String) - what am I doing wrong with it.