Highlighted
Trusted Contributor.. Vanerke Trusted Contributor..
Trusted Contributor..
662 views

XML parsing. Issue with namespaces

Jump to solution

Hello All!

I have an issue with xml parsing. Maybe someone has already come across it.


The issue is with namespaces.

Here is an example of log. Each new event starts from node <packet>:


<jive xmlns="http://www.jivesoftware.org">

<packet xmlns="http://www.jivesoftware.org" status="unknown" timestamp="Oct 20, 2013 03:33:57:153 PM">

<message xmlns="" from="xxxx" to="xxxx"><body>Test message</body>

</message>

</packet>


There are two different namespaces, one is xmlns="http://www.jivesoftware.org, the other one is  xmlns="" (empty).


If I use only namespace http://www.jivesoftware.org in config file then parser misses data in message’s node. If I manually add http://www.jivesoftware.org namespace to xmlns attribute in message node it works well.


I don't know how I can tell parser to work with empty xmlns values .

Any ideas?

P.S. There is no way to change the log itself.

--Roman

Labels (3)
0 Likes
1 Solution

Accepted Solutions
Trusted Contributor.. Vanerke Trusted Contributor..
Trusted Contributor..

Re: XML parsing. Issue with namespaces

Jump to solution

Hi everybody,

finally I found a solution. Spent some time studying XPath

XPath allows to ignore namespaces using a function local-name()=''.

So, I used the following expression as a hop node:

hop.node[0].expression=//*[local-name()='packet' and @status!='unknown' and boolean(./message/body)]

and then I can easily select any nodes and any attributes.

Thanks for the help.

Cheers,

Roman

0 Likes
5 Replies

Re: XML parsing. Issue with namespaces

Jump to solution

Roman - maybe using something like "//message/body" will allow you to skip over looking at the namespace and extract "Test message" from there.

0 Likes
Trusted Contributor.. Vanerke Trusted Contributor..
Trusted Contributor..

Re: XML parsing. Issue with namespaces

Jump to solution

Viktor - attached flexconnector config file and I've already tried '/message/body'. Doesn't work.

--Roman

0 Likes

Re: XML parsing. Issue with namespaces

Jump to solution

Roman - try this (note the double slash "//" before message.  it should look for any node that starts with message and might ignore the namespace):

token[0].expression=$packet//message/body

0 Likes
Trusted Contributor.. Vanerke Trusted Contributor..
Trusted Contributor..

Re: XML parsing. Issue with namespaces

Jump to solution

Victor - tested, doesn't work either

0 Likes
Trusted Contributor.. Vanerke Trusted Contributor..
Trusted Contributor..

Re: XML parsing. Issue with namespaces

Jump to solution

Hi everybody,

finally I found a solution. Spent some time studying XPath

XPath allows to ignore namespaces using a function local-name()=''.

So, I used the following expression as a hop node:

hop.node[0].expression=//*[local-name()='packet' and @status!='unknown' and boolean(./message/body)]

and then I can easily select any nodes and any attributes.

Thanks for the help.

Cheers,

Roman

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.