ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » XPATH issue with namespace qualified XML.

Post new topic  Reply to topic
 XPATH issue with namespace qualified XML. « View previous topic :: View next topic » 
Author Message
wilsonjohn24
PostPosted: Thu Jan 10, 2008 4:49 am    Post subject: XPATH issue with namespace qualified XML. Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Hi,

Problem:
---------

Basically I am trying to use xpath to get some information from XML which is is all namespace qualified...
My problem is I can seem to access the element when they are namespace quatified!

Here is an input XML:
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ez:Notification xmlns:ez='http://www.abcdefg.net'>
<ez:NotificationHeader>
.....

</ez:NotificationHeader>
</ez:Notification>


How I have tried to resolve it?
-----------------------------------

I have tried all 3 parsers XML,XMLNS,XMLNSC and have read http://www.mqseries.net/phpBB2/viewtopic.php?p=164158
and have tried the following combinations all with no luck:** the xml parser was just a stab in the dark:


MbElement xmlElement = inMessage.getRootElement().getLastChild();


MbXPath xpath = new MbXPath("//Notification");
xpath.setDefaultNamespace("ez");
Object o = xmlElement.evaluateXPath(xpath);


MbXPath xpath2 = new MbXPath("//Notification");
xpath2.setDefaultNamespace("www.abcdefg.net");

Object y= xmlElement.evaluateXPath(xpath2);


MbXPath xpath3 = new MbXPath("//Notification");
xpath3.setDefaultNamespace("http://www.abcdefg.net");
Object yy= xmlElement.evaluateXPath(xpath3);



MbXPath xpath4 = new MbXPath("//ez:Notification");
Object yyy= xmlElement.evaluateXPath(xpath4);

MbXPath xpath6 = new MbXPath("//Notification");
Object yyyyy= xmlElement.evaluateXPath(xpath6);


MbXPath xpath7 = new MbXPath("//ez/Notification");
Object yyyyyy= xmlElement.evaluateXPath(xpath7);


Help????
-------------

Can anyone please advise or direct me to a sample?




thanks,



John


Last edited by wilsonjohn24 on Thu Jan 10, 2008 2:01 pm; edited 2 times in total
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Thu Jan 10, 2008 4:53 am    Post subject: XMLNS - Trace Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

(0x01000010):XML = (
(0x05000018):XML = (
(0x06000011): = '1.0'
(0x06000012): = 'UTF-8'
)
(0x06000002): = ' '
(0x01000000):ez:Notification = (
(0x03000000):xmlns:ez = 'http://www.abcdef.net'
(0x02000000): = ' '
(0x01000000):ez:NotificationHeader = (
(0x03000000):destinationOperatorId = 'xxxx'
(0x03000000):issuedDate = '2005-01-01T00:00:02'
(0x03000000):notificationId = '1223'
)
(0x02000000): = ' '
(0x01000000):ez:NotificationBody = (
(0x02000000): = ' '
(0x01000000):ez:NetworkIssueOpened = (
(0x03000000):openedAt = '2008-02-12T15:00:00'
(0x02000000): = ' '
(0x01000000):ez:Case = (
(0x03000000):id = '232323'
(0x02000000): = ' '
(0x01000000):ez:Note = (
(0x02000000): = 'Exchange CLWAP flooded due to burst waterpipe'
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Thu Jan 10, 2008 8:38 am    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Also I have tried the sample
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=/com.ibm.etools.mft.doc/com/ibm/broker/plugin/MbXPath.html


This does not work and still did work even when I correct the typo in the document.


Last edited by wilsonjohn24 on Thu Jan 10, 2008 2:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jan 10, 2008 8:51 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Code:

MbXPath xpath4 = new MbXPath("/Notification");
xpath4.setDefaultNamespace("http://www.abcdefg.net");
List  yy= (List)xmlElement.evaluateXPath(xpath4);


Also, what does it return, that you don't think is right? A null value?

Thirdly, you won't get this to work, ever, with XML domain. As XML Domain will always remove/mangle the namespaces.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Thu Jan 10, 2008 11:57 am    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Basically it is return a empty MBElement[] with no elements. i.e. the size is 0
and when you enumerate over it, no elements are returned. Did not attempt to
cast the result of the evaluate to proper types -so i could debug more easily.

When I de-namespace my xml I can access the elements ok.


Was orginally using XMLNS/XMLNSC,but tried XML parser as I was not having any luck
with the fore mentioned parsers.

------------------------------------------------
Even the simple namespace example from the IBM web site does not seem to work- My desktop
is on the whole very update to date with fix packs etc for the tools et al.


Does the code sample you posted worked ok for yourself?



cheers

John


Last edited by wilsonjohn24 on Thu Jan 10, 2008 1:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
kimbert
PostPosted: Thu Jan 10, 2008 12:12 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Quote:
When I de-namespace my xml I can access the elements ok
That should give you a very strong clue.
Code:
 xpath.setDefaultNamespace("ez");

I suggest that you look at the difference between a namespace URI and a namespace prefix.
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Thu Jan 10, 2008 1:11 pm    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Hi Kimbert thanks for your reponse

I have tried doing as you suggested but it still did not work(see orginal code ), the IBM documentation seemed to suggest it is the namespace URI rather than the prefix that you pass as the argument to the setDefaultNamespace(). I have also tried adding namespaces using the addNamespace() and an hybrid of a few examples - but still no luck.

I have moved the namespace reference around i.e. using them as default, anonymous, top level etc.

IBM Ref: http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=/com.ibm.etools.mft.doc/com/ibm/broker/plugin/MbXPath.html

cheers,

John

ps: I am aware of the difference between namespace uri and namespace
prefix. Some parts of example code posted was just exploring any little tangents off the IBM documented example - so I did not post a fuddy SOS and waste members time
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jan 10, 2008 4:40 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

John -

I haven't actually tried the specific code I posted... But I'm reasonably comfortable that it's a step in the right direction... If you'll notice, it uses the namespace URI rather than the prefix... and it uses a direct path "/" to the root node, rather than searching for every child of "/" that happens to be named "Notification", like "//Notification" should do... unless I completely misunderstand XPath...

It's not a big stretch to assume I completely misunderstand XPath. But it's probably not entirely a safe bet, either.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Fri Jan 11, 2008 1:02 am    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Still does not work by changing to to direct path syntax. I have also tried this on different environments to rule out any local system issues!


The "official" IBM example does not work either ( using XMLNS* parser), even when I fix the typo on line 3.

<aaa xmlns='http://mydomain.com/namespace1'
xmlns:other='http://mydomain.com/namespace2'>
<other:aaa>
<bbb/>
</other:aaa>
<aaa>


MbXPath xp = new MbXPath("/aaa/other:aaa/bbb");
xp.addNamespacePrefix("other", "http://mydomain.com/namespace2");
xp.setDefaultNamespace("http://mydomain.com/namespace2");
List nodeset = (List)message.evaluateXPath(xp);

-----------------------------------------------------------------------

Has anyone in the forum used XPATH + namespace qualified XML?
I seen a few threads on the IBM developer works but none produce a conclusion nor correct sample.
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Fri Jan 11, 2008 3:54 am    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

I can use some alternative XPATH functions to navigate to the element I want so I know it is present.

MbXPath xpath1 =
new MbXPath("/*/*[position() = last()]/*[position() = last()]");


and also traverse it using MbElement.getChild*() etc ....

This returns the correct element also...

-------------------------

But if I try to refer by name space..

MbXPath xpath1 =
new MbXPath("/*/*[position() = last()]/ez:Notification");
xpath1.addNamespacePrefix("ez","http://www.foo.co.uk");

it fails.

-----------------------------------------------
Summary:
=======
Unless their is some option I have missed ( or a major issue on myside) I am having serious trouble accepting that xpath with namespaces on wmb is a plausable technical option?


I have read that the implemenation is 1.0 XPATH compliant with a few difference around the way AXIS works. So I could accept that the match any node options i.e // may not work.
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Jan 11, 2008 5:28 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Try this. Not tested, but it comes from a very reliable source:
Code:
MbXPath xpath = new MbXPath("//ez:Notification");
xpath.addNamespacePrefix("ez", "http://www.abcdefg.net ");
Object o = xmlElement.evaluateXPath(xpath);
Back to top
View user's profile Send private message
wilsonjohn24
PostPosted: Mon Jan 14, 2008 10:16 am    Post subject: Reply with quote

Voyager

Joined: 02 Feb 2007
Posts: 93
Location: Scotland

Thanks for your code snippet... But it does not work for me.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Mon Jan 14, 2008 11:36 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

wilsonjohn24 wrote:
Thanks for your code snippet... But it does not work for me.


Make sure you're not using plain XML domain - no namespaces means NO name spaces.

Make sure you're using Broker v6, at least CSD/FP 003... FP >=005 is better.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » XPATH issue with namespace qualified XML.
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.