Author |
Message
|
newbeeMB |
Posted: Mon Apr 27, 2015 11:45 pm Post subject: Accessing array element within an array |
|
|
Newbie
Joined: 27 Apr 2015 Posts: 7
|
Hello All,
I'm new to MB and im trying to do this:
Following is my XML message structure:
Code: |
<EmployeeList>
<Empl maxOccurs=unbounded>
<Name>
<ID>
<Skills>
<SkillName maxOccurs=unbounded> |
Im trying to filter the employees who has java skills using the following ESQL:
Code: |
FOR source as InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName" AS I(I.SkillName='Java') DO
SET OutputRoot.XMLNSC.EmployeeList.Empl[i]=
SELECT I.Name, I.ID FROM InputRoot.XMLNSC.EmployeeList.Empl[i] AS I;
END FOR; |
I get the following error on the FOR ANY statement:
Syntax error: Valid options include IDENTIFIER SIMPLE_FUNCTION.
I referred to the esql pdf example for FOR ANY.
Kindly assist. |
|
Back to top |
|
 |
iibmate |
Posted: Tue Apr 28, 2015 12:54 am Post subject: Re: Accessing array element within an array |
|
|
 Apprentice
Joined: 17 Mar 2015 Posts: 38 Location: Perth, WA
|
newbeeMB wrote: |
FOR source as InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName" AS I(I.SkillName='Java') DO
SET OutputRoot.XMLNSC.EmployeeList.Empl[i]=
SELECT I.Name, I.ID FROM InputRoot.XMLNSC.EmployeeList.Empl[i] AS I;
END FOR;
|
Please paste complete input message and esql code, for our analysis.
(1) please use outer loops reference in inner loop.
(2) SET OutputRoot.XMLNSC.EmployeeList.Empl[i]
Is the variable "i" initialized ? then with what value. Where is the incrementing statement for this variable ? |
|
Back to top |
|
 |
newbeeMB |
Posted: Tue Apr 28, 2015 9:07 am Post subject: |
|
|
Newbie
Joined: 27 Apr 2015 Posts: 7
|
Thank you for the prompt response. Here is the complete input message:
Code: |
<?xml version="1.0" encoding="UTF-8"?><EmployeeList>
<Empl>
<Name>John</Name>
<EmpID>2468</EmpID>
<Skills>
<SkillName>Java</SkillName>
<SkillName>C++</SkillName>
</Skills>
</Empl>
<Empl>
<Name>Mark</Name>
<EmpID>1456</EmpID>
<Skills>
<SkillName>C</SkillName>
<SkillName>Android</SkillName>
</Skills>
</Empl>
</EmployeeList> |
And here is the complete ESQL:
Code: |
CREATE PROCEDURE CopyEntireMessage() BEGIN
DECLARE i INTEGER 1;
FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName"[] AS I (I.SkillName='Java') DO
SET OutputRoot.XMLNSC.EmployeeList.Empl[i].Name=InputRoot.XMLNSC.EmployeeList.Empl[i].Name;
SET OutputRoot.XMLNSC.EmployeeList.Empl[i].EmpID=InputRoot.XMLNSC.EmployeeList.Empl[i].EmpID;
END FOR;
SET i=i+1;
END FOR;
END; |
Kindly assist. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Apr 28, 2015 10:17 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
newbeeMB wrote: |
And here is the complete ESQL:
Code: |
CREATE PROCEDURE CopyEntireMessage() BEGIN
DECLARE i INTEGER 1;
FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName"[] AS I (I.SkillName='Java') DO
SET OutputRoot.XMLNSC.EmployeeList.Empl[i].Name=InputRoot.XMLNSC.EmployeeList.Empl[i].Name;
SET OutputRoot.XMLNSC.EmployeeList.Empl[i].EmpID=InputRoot.XMLNSC.EmployeeList.Empl[i].EmpID;
END FOR;
SET i=i+1;
END FOR;
END; |
|
Don't put user code in the generated procedures. If something causes the Toolkit to regenerate the procedure, your code will be lost. Put it in the main body after the call to that procedure.
The correct form of what you've tried to write is:
Code: |
FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY source.Skills.SkillName[] AS I (I.SkillName='Java') DO
CREATE LASTCHILD OF OutputRoot.XMLNSC.EmployeeList.Empl NAME "Name" VALUE source."Name";
CREATE LASTCHILD OF OutputRoot.XMLNSC.EmployeeList.Empl NAME EmpID VALUE source.EmpId;
END FOR;
END FOR;
|
Untested, E&OE and note the double quotes round the tag called "Name" as it's a reserved word in ESQL
You could get the same result with something like:
Code: |
SET OutputRoot.XMLNSC.EmployeeList.Empl[] = SELECT I."Name", I.EmpID FROM InputRoot.XMLNSC.EmployeeList.Empl AS I WHERE I.Skils.SKillName = 'Java'
|
Other coding solutions which are variations or combinations of these two methods are possible and highly functional. This cat can be skinned in a variety of ways. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
iibmate |
Posted: Tue Apr 28, 2015 5:34 pm Post subject: |
|
|
 Apprentice
Joined: 17 Mar 2015 Posts: 38 Location: Perth, WA
|
No arrays in IIB, only lists. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 29, 2015 4:26 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
iibmate wrote: |
No arrays in IIB, only lists. |
Lists, and elements in a logical message tree. |
|
Back to top |
|
 |
|