Author |
Message
|
chaitanyauk |
Posted: Fri Nov 10, 2017 5:05 am Post subject: Accessing array elements in xml in java compute node |
|
|
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 |
|
 |
timber |
Posted: Fri Nov 10, 2017 6:11 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
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 |
|
 |
chaitanyauk |
Posted: Thu Nov 16, 2017 3:37 am Post subject: |
|
|
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 |
|
 |
souciance |
Posted: Fri Nov 17, 2017 4:03 pm Post subject: Re: Accessing array elements in xml in java compute node |
|
|
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 |
|
 |
fjb_saper |
Posted: Sat Nov 18, 2017 4:52 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20763 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 |
|
 |
|