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 » Accessing array elements in xml in java compute node

Post new topic  Reply to topic
 Accessing array elements in xml in java compute node « View previous topic :: View next topic » 
Author Message
chaitanyauk
PostPosted: Fri Nov 10, 2017 5:05 am    Post subject: Accessing array elements in xml in java compute node Reply with quote

Apprentice

Joined: 16 Apr 2017
Posts: 30

Hi,

i have an XML data with array elements.

<Root>
<data>
<param>abc</param>
<param>efg</param>
<param>xyz</param>
<param>def</param>
<data>
</Root>

How do I access nth element in an array?
will this work?
inMessage.getRootElement().getFirstElementByPath(/XMLNSC/Root/data/param[3]).getValueAsString()

Thanks
Back to top
View user's profile Send private message
timber
PostPosted: Fri Nov 10, 2017 6:11 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

The JAXB API is a much nicer API than the stock Java API. Just import your XSD when adding the JavaCompute node, and it will generate the bindings for you.
Back to top
View user's profile Send private message
chaitanyauk
PostPosted: Thu Nov 16, 2017 3:37 am    Post subject: Reply with quote

Apprentice

Joined: 16 Apr 2017
Posts: 30

Thanks for the reply.

But I don't have any schema.
I just want to convert input XML message to character.
Back to top
View user's profile Send private message
souciance
PostPosted: Fri Nov 17, 2017 4:03 pm    Post subject: Re: Accessing array elements in xml in java compute node Reply with quote

Disciple

Joined: 29 Jun 2010
Posts: 169

chaitanyauk wrote:
Hi,

i have an XML data with array elements.

<Root>
<data>
<param>abc</param>
<param>efg</param>
<param>xyz</param>
<param>def</param>
<data>
</Root>

How do I access nth element in an array?
will this work?
inMessage.getRootElement().getFirstElementByPath(/XMLNSC/Root/data/param[3]).getValueAsString()

Thanks


You can use Jackson for xpath and or javax..
http://www.baeldung.com/java-xpath

Anyway just pick an approach and test it.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Nov 18, 2017 4:52 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

chaitanyauk wrote:
Thanks for the reply.

But I don't have any schema.
I just want to convert input XML message to character.

Have you tried parsing as a BLOB or use the asbitstream function?

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Accessing array elements in xml in java compute node
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.