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 XML tags and their values

Post new topic  Reply to topic
 Accessing XML tags and their values « View previous topic :: View next topic » 
Author Message
Harman
PostPosted: Thu Oct 29, 2020 6:07 am    Post subject: Accessing XML tags and their values Reply with quote

Newbie

Joined: 22 Apr 2020
Posts: 9

Hi , I have XML structure like this :

Code:
<parent>
      <first>
        <second>
            <third attr="name" attr1="test1" />
            <third attr="age" attr1="25" />
        </second>
        <second w="0">
            <third attr="name" attr1="test2" />
            <third attr="age" attr1="26" />
        </second>
      </first>
</parent>


I want to access the attr1 that is test1 using attr that is name , is it possible at all ?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Oct 29, 2020 8:33 am    Post subject: Re: Accessing XML tags and their values Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Harman wrote:
I want to access the attr1 that is test1 using attr that is name , is it possible at all ?


Yes.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Harman
PostPosted: Thu Oct 29, 2020 9:09 am    Post subject: Reply with quote

Newbie

Joined: 22 Apr 2020
Posts: 9

@Vitor I tried playing around with XML.Element and XML.Attr but I dont think I am doing it in a correct way.

Something like
DECLARE test_var CHAR FIELDVALUE(InputRoot.XMLNSC.parent.first.second[1].(XML.Element)f)

Could you please provide your inputs on this?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Oct 29, 2020 10:48 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Wouldn't it be more like:

Code:

DECLARE test_var CHAR FIELDVALUE(InputRoot.XMLNSC.parent.first.second[1].third[1].(XML.Attr)attr)

_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Harman
PostPosted: Thu Oct 29, 2020 7:14 pm    Post subject: Reply with quote

Newbie

Joined: 22 Apr 2020
Posts: 9

@Vitor , ok . So the <third> is kind of array again which needs to be handled in a loop like <second> . Got it . Thank you !
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Oct 30, 2020 4:36 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Harman wrote:
@Vitor , ok . So the <third> is kind of array again which needs to be handled in a loop like <second> . Got it .


No you have not.

In your example, <first> is a complex XML type, made up of an iteration of the complex type <second>. That, in turn, is made up of an iteration of the simple type <third>, which also has attributes.

This is basic XML and nothing to do with IIB/ACE. Ask Google for a good XML tutorial and read it until you understand you can't just ignore an XML element (like <third>).

They're not an array, they are just an iterative list. ESQL allows you to use array indexes to reference them but on an XML document of any size this is hideously inefficient. ESQL does not maintain a pointer to the list so when you access element n, the software starts with first element and counts through the document n times. This is fine for small documents like your example, but with an iteration of 100 elements you'll really see that run time extend. Much better is to define a user pointer in code and move that through the list yourself. As I said, not needed in your small example but it's a good idea to get into the habit.

Because this behavior can cause a "gotcha". If you access elements by index (as you are) and delete an element (good practice in large documents, saves memory), the count changes.

Consider this example:

You access element 30 in the list. The ESQL element[30] causes the broker to count until it finds the 30th element. You process this and remove it from the tree. You then access element[31] in your code (probably by incrementing a loop variable). The broker will count until it reaches 31 taking no account of the element which is now deleted. So the element you find at position 31 is the element which, prior to deletion, was element 32 and an element is never processed.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
timber
PostPosted: Sat Oct 31, 2020 2:27 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

@Vitor: I think Harman probably needs a SELECT statement, or else at last one loop. But I cannot be sure...

@Harman : I do not understand exactly what you need to do. Please can you include some more examples.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Tue Nov 10, 2020 10:24 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

Harman wrote:
@Vitor I tried playing around with XML.Element and XML.Attr but I dont think I am doing it in a correct way.

It's not always necessary to use parser constants to qualify the type of field references. But if the code does use them, they should match the parser. Use XMLNSC parser constants with the XMLNSC parser, such as (XMLNSC.Field) or (XMLNSC.Attribute), instead of XML parser constants.
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 » Accessing XML tags and their values
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.