Author |
Message
|
swaugh |
Posted: Mon Feb 25, 2008 5:49 pm Post subject: XMLNS parsing |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
Hi ,
I am having an issue parsing XML attributes using XMLNS domain.
The Input message looks like this
<eims2:Role type="Sales">
<oa9:Code>SalesResource</oa9:Code>
</eims2:Role>
<eims2:Role type="FMSRole">
<oa9:Code>RGSHH</oa9:Code>
</eims2:Role>
I am trying to parse the element value of oa9:code for an attribute value of Role type ="FMSRole". I need to access the value "RGSHH" from the above tree.
I have the following esql
SET VFMSJOBROLECODE = THE(Select Item I from InputRoot.eims2:Role.oa9:Code AS I where I.(XML.Attribute)type='FMSRole');
but the above esql statement doesnt work.
Any help in this regard is appreciated
Thanks,
Swaugh |
|
Back to top |
|
 |
gregop |
Posted: Tue Feb 26, 2008 12:11 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2006 Posts: 81
|
Quote: |
SET VFMSJOBROLECODE = THE(Select Item I from InputRoot.eims2:Role.oa9:Code AS I where I.(XML.Attribute)type='FMSRole');
|
Firstly (possibly a typo in your post) you're using XMLNS parser so you want InputRoot.XMLNS
Secondly you want to look over each instance of eims2:role not just the first instance of eims2:role.oa9:Code you'll need to do something like:
SET VFMSJOBROLECODE = THE(Select Item I.oa9:Code from InputRoot.XMLNS.eims2:Role[] AS I where I.(XML.Attribute)type='FMSRole'); |
|
Back to top |
|
 |
swaugh |
Posted: Tue Feb 26, 2008 2:02 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
Thanks for the reply. when i use the suggested esql
SET VFMSJOBROLECODE = THE(Select Item I.oa9:Code from InputRoot.XMLNS.eims2:Role[] AS I where I.(XML.Attribute)type='FMSRole');
i get the first value correctly, that is the oa9:Code= 'SalesResource when type is 'Sales', if i change the value to 'FMSRole' then i get null assignment. Looks like the syntax
THE(Select Item I from InputRoot.eims2:Role.oa9:Code AS I where I.(XML.Attribute)type='FMSRole');
returns the first occurence. Am i missing anything. |
|
Back to top |
|
 |
mgk |
Posted: Tue Feb 26, 2008 3:45 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
The attribute type does not exist on the oa9:Code element, it exists on the eims2:Role element. And when you say "AS I" I becomes the element at the end of the path, in this case oa9:Code. Therefore, you are going too "deep" in the message, you need to stop at eims2:Role. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
swaugh |
Posted: Tue Feb 26, 2008 4:04 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
Tis is the syntax I have
SET VFMSJOBROLECODE = The(Select Item I.oa9:Code from VTERRITORYHEADER.eims2:Role[] AS I where VTERRITORYHEADER.eims2:Role.(XML.Attribute)type='FMSRole');
It yields null. |
|
Back to top |
|
 |
swaugh |
Posted: Tue Feb 26, 2008 4:25 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
It looks like assignment issue. I have declared VFMSJOBROLECODE as character and its not able to hold the result arising from
SET VFMSJOBROLECODE = THE(Select Item I from InputRoot.eims2:Role.oa9:Code AS I where I.(XML.Attribute)type='FMSRole');
If i change the assignment variable from SET VFMSJOBROLECODE TO
SET OUTPUTROOT.XML.FMSJOBROLECODE, i am able to see the value in the output root tree.
I guess the assignment type is the issue. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Feb 27, 2008 1:37 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Code: |
SET OUTPUTROOT.XML.FMSJOBROLECODE |
There is no good reason to write new code which uses the XML domain. Please switch to XMLNS. |
|
Back to top |
|
 |
swaugh |
Posted: Tue Mar 04, 2008 5:49 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
Adding to the same XML complex structure, i have an XML tree something like this
<Territory>
<eims2:Role type="Sales">
<oa9:Code>SalesResource</oa9:Code>
</eims2:Role>
<eims2:Role type="FMSRole">
<oa9:Code>RGSHH</oa9:Code>
</eims2:Role>
<eims2:Role type= "FRSRole">
<oa9:Code>GTS000000001</oa9:Code>
<oa9:Description>TEST FRS GTS ROLE</oa9:Description>
<eims2:SubRole type="BrandGroup">
<oa9:Description>GTS</oa9:Description>
</eims2:SubRole>
<eims2:SubRole type="ResourceCategory">
<oa9:Description>TESTGTS</oa9:Description>
</eims2:SubRole> <eims2:SubRole type="ProductLevel1">
<oa9:Description>ABC</oa9:Description>
</eims2:SubRole>
<eims2:SubRole type="ProductLevel2">
<oa9:Description>123</oa9:Description>
</eims2:SubRole>
<eims2:SubRole type="ProductLevel3">
<oa9:Description>DEF</oa9:Description>
</eims2:SubRole>
</eims2:Role>
</Territory>
I am trying to parse the value of sub role type = Resource Category (value is TESTGTS)
<eims2:SubRole type="ResourceCategory">
<oa9:Description>TESTGTS</oa9:Description>
</eims2:SubRole>[/color]
and I have the following ESQL code
SET VBRANDGROUP = The(Select Item I.eims2:SubRole.oa9:Description from InputRoot.XMLNS.Territory.eims2:Role[] AS I where I.(XML.Attribute)type='FRSRole' and I.(XML.Attribute)type='ResourceCategory');
I am getting VBRANDGROUP as Null.
If i modify the above ESQL where condition to
SET VBRANDGROUP = The(Select Item I.eims2:SubRole.oa9:Description from InputRoot.XMLNS.Territory.eims2:Role[] AS I where I.(XML.Attribute)type='FRSRole');
i get the first occurence oa9:Description value = GTS.
How do i get the oa9:Description value for eims2:SubRole type="ResourceCategory">
<oa9:Description>TESTGTS</oa9:Description>
</eims2:SubRole>[/color]
thanks,
Swaugh |
|
Back to top |
|
 |
mgk |
Posted: Wed Mar 05, 2008 2:23 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
I may be misunderstanding what you are trying to do, but this code:
Code: |
... AS I.(XML.Attribute)type='FRSRole' and I.(XML.Attribute)type='ResourceCategory') |
Will only match elements that have two type attributes, one with a value of 'FRSRole' and one with a value of 'ResourceCategory'. And as I believe that you cannot have two attributes of the same name on an element in XML then this will never match anything, so you will always get NULL back.
If you want to find element with the type of 'ResourceCategory' what is wrong with using;
Code: |
... AS I where I.(XML.Attribute)type='ResourceCategory'? |
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
swaugh |
Posted: Wed Mar 05, 2008 5:32 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
If u see Sub Role Xml tag is under the Role tag of type ='FRSRole'
I tried the esql like
SET VBRANDGROUP = The(Select Item I.eims2:SubRole.oa9:Description from InputRoot.XMLNS.Territory.eims2:Role[] AS I where I.eims2:SubRole.(XML.Attribute)type='ResourceCategory');
still it yields null. Looks like its not nvaigating to the SubRole element under Role type="FRSRole"
Only code thats navigating to SubRole Tree is
Code: |
SET VBRANDGROUP = The(Select Item I.eims2:SubRole.oa9:Description from InputRoot.XMLNS.Territory.eims2:Role[] AS I where I.(XML.Attribute)type='FRSRole'); |
where we get the first occurence of description value under sub role type = BrandGroup
any ideas, where i am committing the mistake? |
|
Back to top |
|
 |
gregop |
Posted: Thu Mar 06, 2008 12:09 am Post subject: |
|
|
Voyager
Joined: 24 Nov 2006 Posts: 81
|
You'll be needing a select within a select.
This snippet will return the Roles that you are interested in:
Select I from InputRoot.eims2:Role[] AS I where I.(XML.Attribute)type='FMSRole');
Then select from that list to return the SubRole required so something like this:
SET VBRANDGROUP = The(Select Item J.eims2:SubRole.oa9:Description from (Select I from InputRoot.eims2:Role[] AS I where I.(XML.Attribute)type='FMSRole') AS J WHERE J.eims2:SubRole.(XML.Attribute)type='ResourceCategory'); |
|
Back to top |
|
 |
swaugh |
Posted: Thu Mar 06, 2008 5:34 pm Post subject: |
|
|
Apprentice
Joined: 15 Jun 2006 Posts: 37
|
Thanks for the tip on nested select.
Code: |
SET VBRANDGROUP = The(Select Item J.eims2:SubRole.oa9:Description from (Select I from InputRoot.eims2:Role[] AS I where I.(XML.Attribute)type='FMSRole') AS J WHERE J.eims2:SubRole.(XML.Attribute)type='ResourceCategory'); |
but the above mentioned code is returning ESQL error, the esql compiler is not liking the nested select in the from clause. any ideas?
thanks,
Swaugh |
|
Back to top |
|
 |
|