Author |
Message
|
sraghukumar |
Posted: Sun Feb 09, 2014 10:15 am Post subject: Find the count of element name |
|
|
Apprentice
Joined: 15 Feb 2011 Posts: 49
|
Hi There,
I have a requirement to count the number of elements in the incoming message. The trick part is i need to find the name of the element first.
For example. In the below xml message, i have a complex element by name Employees, three simple elements, Where each element name is Employee3, the Number 3 in the element is because there are three Employee3 in the incoming message.
Sample.xml
<Company>
<Employees>
<Employee3>010101</Employee3>
<Employee3>010102</Employee3>
<Employee3>010103</Employee3>
</Employees>
</Company>
Now the requirement is to find the count of Employee3 in this case the count is 3, But in general Number 3 is variable. it can go from 1 to N.
The question is how to find count of EmployeeN, any input is helpful.
[/i] _________________ -----------
Raghu |
|
Back to top |
|
 |
smdavies99 |
Posted: Sun Feb 09, 2014 11:05 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
You can find the name of the first child of <Employees> using the fieldname function.
This allows you to cater for a different tag name.
Then the cardinality function may help getting the count of the number. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
Gralgrathor |
Posted: Mon Feb 10, 2014 2:13 am Post subject: Re: Find the count of element name |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
sraghukumar wrote: |
Code: |
<Company>
<Employees>
<Employee3>010101</Employee3>
<Employee3>010102</Employee3>
<Employee3>010103</Employee3>
</Employees>
</Company>
|
|
Code: |
DECLARE aName CHARACTER FIELDNAME(InputBody.Company.Employees.*[>]);
DECLARE aCount CHARACTER CARDINALITY(InputBody.Company.Employees.*[]); |
Something like that? Assuming that all children of <Employees> have the same fieldname, of course. |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Feb 10, 2014 2:55 am Post subject: Re: Find the count of element name |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
Gralgrathor wrote: |
sraghukumar wrote: |
Code: |
<Company>
<Employees>
<Employee3>010101</Employee3>
<Employee3>010102</Employee3>
<Employee3>010103</Employee3>
</Employees>
</Company>
|
|
Code: |
DECLARE aName CHARACTER FIELDNAME(InputBody.Company.Employees.*[>]);
DECLARE aCount CHARACTER CARDINALITY(InputBody.Company.Employees.*[]); |
Something like that? Assuming that all children of <Employees> have the same fieldname, of course. |
It is not a good idea to write the code for someone else. Just give him/her the clues and let them try for themselves. Or are they getting paid for you to code their ESQL ? |
|
Back to top |
|
 |
Gralgrathor |
Posted: Mon Feb 10, 2014 3:30 am Post subject: Re: Find the count of element name |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
dogorsy wrote: |
It is not a good idea to write the code for someone else. |
Probably not. But I feel bad about just swearing at people and telling them to RTFM. After all, I've asked my share of stupid questions too, and I appreciated the help I got from the people here. |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Feb 10, 2014 3:37 am Post subject: Re: Find the count of element name |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
[quote="Gralgrathor"]
dogorsy wrote: |
But I feel bad about just swearing at people and telling them to RTFM. |
There are other options. |
|
Back to top |
|
 |
Gralgrathor |
Posted: Mon Feb 10, 2014 4:06 am Post subject: Re: Find the count of element name |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
dogorsy wrote: |
There are other options. |
By my oath, I am not a violent man. I don't go around killing people just for asking questions. |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Feb 10, 2014 4:10 am Post subject: Re: Find the count of element name |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
Gralgrathor wrote: |
dogorsy wrote: |
But I feel bad about just swearing at people and telling them to RTFM. |
There are other options. |
|
|
Back to top |
|
 |
sraghukumar |
Posted: Mon Feb 10, 2014 7:31 am Post subject: Thanks for the Response |
|
|
Apprentice
Joined: 15 Feb 2011 Posts: 49
|
Hi smdavies99 and Gralgrathor,
Thank for the response guys, i really appreciate it.
I can't take go by your suggestion, i should have put my question correct at first place, in my sample xml, there are so many other elements, but i am interested in count of <EmployeeN>, that make little hard to find out.
<Company>
<Employees>
<team>sap</team>
...etc
<Employee3>010101</Employee3>
<Employee3>010102</Employee3>
<Employee3>010103</Employee3>
</Employees>
</Company> _________________ -----------
Raghu |
|
Back to top |
|
 |
Gralgrathor |
Posted: Mon Feb 10, 2014 7:41 am Post subject: Re: Thanks for the Response |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
sraghukumar wrote: |
but i am interested in count of <EmployeeN> |
Then look at the code I posted. It'll give you the name of the first element of the list and the number of siblings. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Feb 11, 2014 12:50 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I have a requirement to count the number of elements in the incoming message. |
I think it is time to ask an important question.
Why do you need to know the count? _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
Gralgrathor |
Posted: Tue Feb 11, 2014 1:00 am Post subject: |
|
|
Master
Joined: 23 Jul 2009 Posts: 297
|
kimbert wrote: |
Why do you need to know the count? |
More importantly, who in his right mind would design an XML schema in which the number of elements is encoded into the field name? Isn't that, like, insane? |
|
Back to top |
|
 |
|