Author |
Message
|
EAI Developer |
Posted: Fri Feb 24, 2012 9:45 am Post subject: MbXpath issue |
|
|
 Centurion
Joined: 30 Nov 2005 Posts: 101 Location: US
|
Hi All,
I am working with MbXpath on the xml meassge with namespaces, where expression is returning null(always) when evaluateXpath. I did work with MbXpath in the past, but without namespaces. I used altova xml spy and xpath checker to generate the expression, which is giving the value I want, but when I put the same in MbXpath it is not working. Can you please help me on this. Thanks !
Request Xml: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:feat="http://icm.xxx.com/soap/xxx" xmlns:com="http://icm.xxx.com/data/common" xmlns:set="http://icm.xxx.com/data/settings" xmlns:pres="http://icm.xxx.com/data/presence"><soapenv:Header/><soapenv:Body><feat:updateCurrentSettings><feat:sessionId com:SessionId="0332116575276"/>
Code:
MbXPath expr4 = new MbXPath("/soapenv:Envelope/soapenv:Body/feat:updateCurrentSettings/feat:sessionId/@com:SessionId");
expr4.addNamespacePrefix("feat","http://icm.xxx.com/soap/xxx");
expr4.addNamespacePrefix("com","http://icm.xxx.com/data/common");
expr4.addNamespacePrefix("set","http://icm.xxx.com/data/settings");
expr4.addNamespacePrefix("pres","http://icm.xxx.com/data/presence");
List list5 = (List)mRequest.evaluateXPath(expr4);
String sRequestMsg="";
if (!list5.isEmpty()) {
list5.size();
Iterator li = list5.iterator();
MbElement mEle = null;
while(li.hasNext()) {
mEle = (MbElement)li.next();
sRequestMsg = mEle.getValueAsString(); }
}
Here I am looking for the value of the attribute(com:SessionId) inside the xml tag <feat:sessionId>
I have even tried this : MbXPath expr4 = new MbXPath("//feat:sessionId/@*");
Message Broker v7.0.2 and on Windows Xp. _________________ ___________________
Regards,
EAI Developer. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Feb 24, 2012 10:10 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
You may like using MessageSets with ESQL better than XPath. The toolkit provides namespace helps (CTRL+SPACE BAR) when using ESQL. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
EAI Developer |
Posted: Fri Feb 24, 2012 10:27 am Post subject: |
|
|
 Centurion
Joined: 30 Nov 2005 Posts: 101 Location: US
|
Hi,
I have to use java compute node, we do not use ESQL for some reason.
btw, in the below code snippet,
mRequest = globalEnv.getFirstElementByPath("./PCM/Request_xml") where i am setting the parser as "XMLNSC". stil no luck. _________________ ___________________
Regards,
EAI Developer. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Feb 24, 2012 10:30 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Hahahahahaha.
Who made the decision to outlaw ESQL in your work site?
I went to the doctor once. I pointed at my hand. I said "it hurts when I do that." Doctor said, don't do that! _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Fri Feb 24, 2012 10:45 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
Who made the decision to outlaw ESQL in your work site? |
I think we've done this to death on another thread. I know you enjoy throwing the same subject up until people agree with you, but we don't need this again. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Feb 24, 2012 10:49 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Vitor wrote: |
lancelotlinc wrote: |
Who made the decision to outlaw ESQL in your work site? |
I think we've done this to death on another thread. I know you enjoy throwing the same subject up until people agree with you, but we don't need this again. |
You have something against ESQL, Vitor? _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Vitor |
Posted: Fri Feb 24, 2012 10:51 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
lancelotlinc wrote: |
You have something against ESQL, Vitor? |
No, it's more personal. Your posts are becoming less useful and more predictable. This is not your blog, and we don't have duplicate threads here. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Feb 24, 2012 12:36 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Your XPath expression looks OK to me - although you don't actually need this line:
Code: |
expr4.addNamespacePrefix("set","http://icm.xxx.com/data/settings"); |
...because your XPath expression never refers to that namespace.
Did you notice that it was easier to read that line of code, because I wrapped it in [c o d e] tags? Please do the same, as a courtesy to the people who are reading your question.
Next steps:
- Assume that the XPath engine in WMB works correctly. It usually does a pretty good job.
- Add a Trace node just before the JCN with pattern set to {Root}
- Take a user trace
The user trace will show you the exact message tree that the XPath engine is working against. That seems like a useful piece of diagnostic info
You may even get lucky, and find something else in the user trace that leads you to understand the problem. |
|
Back to top |
|
 |
rekarm01 |
Posted: Fri Feb 24, 2012 4:17 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
EAI Developer wrote: |
Code: |
mRequest = globalEnv.getFirstElementByPath("./PCM/Request_xml") |
|
What is globalEnv set to? Which message tree? What does the message tree structure look like?
EAI Developer wrote: |
Code: |
MbXPath expr4 = new MbXPath("/soapenv:Envelope/soapenv:Body/feat:updateCurrentSettings/feat:sessionId/@com:SessionId");
expr4.addNamespacePrefix("feat","http://icm.xxx.com/soap/xxx");
expr4.addNamespacePrefix("com","http://icm.xxx.com/data/common");
expr4.addNamespacePrefix("set","http://icm.xxx.com/data/settings");
expr4.addNamespacePrefix("pres","http://icm.xxx.com/data/presence"); |
|
The namespace prefix for "soapenv" is missing; "set" and "pres" aren't used. |
|
Back to top |
|
 |
EAI Developer |
Posted: Mon Feb 27, 2012 2:38 pm Post subject: |
|
|
 Centurion
Joined: 30 Nov 2005 Posts: 101 Location: US
|
globalEnv is set to /PCM/Request_xml, where Request_xml = <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:feat="http://icm.xxx.com/soap/xxx" xmlns:com="http://icm.xxx.com/data/common" xmlns:set="http://icm.xxx.com/data/settings" xmlns:pres="http://icm.xxx.com/data/presence"><soapenv:Header/><soapenv:Body><feat:updateCurrentSettings><feat:sessionId com:SessionId="0332116575276"/>.
I have tried this xpath, where i don't need set 'all' namespace prefixes. Issue is till there.
Code: |
MbXPath expr4 = new MbXPath("//feat:sessionId/[@*]");
|
_________________ ___________________
Regards,
EAI Developer. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Feb 27, 2012 4:09 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please excuse the question, but...
I assume that you know that the MbXPath facility operates on the message tree, and *not* on an (unparsed) XML string? So globalEnv needs to be the root of an XMLNSC message tree, and NOT a character string.
Have you tried the steps that I suggested in my previous post? How about putting in a Trace node and then posting the tree structure. |
|
Back to top |
|
 |
EAI Developer |
Posted: Mon Mar 05, 2012 6:06 am Post subject: |
|
|
 Centurion
Joined: 30 Nov 2005 Posts: 101 Location: US
|
Hi,
Thanks for the help. I was creating xmlnsc parser after getting the xml from the global env. Now, I have created the xmlnsc parser in the global env, before injecting xml message into global env, which resolved the issues. _________________ ___________________
Regards,
EAI Developer. |
|
Back to top |
|
 |
|