Author |
Message
|
ydeonia |
Posted: Sat Apr 27, 2013 2:33 am Post subject: Fetching the attribute values from XML |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Hi
I am setting some input XML values into output XML format . There are some fetching conditions and someone please advice me if I am doing it correctly.
The input XML structure is like
Code: |
<Classification>
<Description>MRF</Description>
<Codes>
<Code Name="BRAND">002</Code>
</Codes>
</Classification>
<Classification Type="BRAND">
<Codes>
<Code>002</Code>
</Codes>
</Classification>
<Classification Type="BRAND">
<Description>MRF</Description>
</Classification>
<Classification>
<Description>GPL RADIAL ROUTIER LPPL</Description>
<Codes>
<Code Name="DSCG CATEGORY">EA10</Code>
</Codes>
</Classification>
<Classification>
<Description>GPL RADIAL ROUTIER</Description>
<Codes>
<Code Name="LPR SUB FAMILY">PG1</Code>
</Codes>
</Classification>
|
Now the requirement is like I need to get the values from the above xml
SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Classification/Codes/Code/@name='Brand'
I have written for this like
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd= THE (SELECT ITEM FIELDVALUE(T) FROM itemMaster.(XMLNSC.Field).*:ItemMasterHeader.*:Classification.*:Codes.*:Code AS T WHERE FIELDVALUE(T.(XMLNSC.Attribute)name) = 'BRAND'); |
Will the above will fetch the value for attribute for name =BRAND
Please anybody advice me if I am correct or not.
Thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Apr 27, 2013 8:03 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Don't use an index to navigate within a table. Use a reference and move to next / previous sibling...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Sat Apr 27, 2013 10:08 am Post subject: Re: Fetching the attribute values from XML |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
ydeonia wrote: |
Will the above will fetch the value for attribute for name =BRAND |
What happens when you try it?
ydeonia wrote: |
Please anybody advice me if I am correct or not. |
You could have found that out with one simple test much quicker than waiting for a response here.
I doubt that ESQL will do what you want it to. Especially as there are 2 tags with the Type attribute set to "BRAND" _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqsiuser |
Posted: Sat Apr 27, 2013 12:00 pm Post subject: Re: Fetching the attribute values from XML |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Just go through the input message with while&LASTMOVE, references and move first/next child and on each structure check for your condition. Then create the OutputRoot based on that (also use references on the OutputRoot).
I have no doubt that you may also achieve your requirement with an ESQL-SELECT.
Its just me (and others) just wouldn't do it that way. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
Vitor |
Posted: Sat Apr 27, 2013 2:05 pm Post subject: Re: Fetching the attribute values from XML |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqsiuser wrote: |
I have no doubt that you may also achieve your requirement with an ESQL-SELECT.
Its just me (and others) just wouldn't do it that way. |
There's seldom only one way to meet a requirement. In many cases the "best" solution is a subjective choice & of course must take account of personal coding style.
But SELECT tends to be more efficient at run time & for what the OP appears to attempting I'd do it with a SELECT.
That doesn't make it the better choice, nor does it make LASTMOVE with a reference "wrong". I'm just sayin... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
ydeonia |
Posted: Sat Apr 27, 2013 6:15 pm Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Thanks all for your valuable input . But your comments make me more confused. I am sorry to say but none of your comments made me confident about the way I am doing so.
My problem is to ftech the values from complex XML structure like
Code: |
- <Specification type="PHYSICAL">
+ <Property>
<NameValue name="TIRE TYPE">TUBELESS</NameValue>
</Property>
</Specification>
+ <Specification Type="LONG DESCRIPTION">
- <Property>
<NameValue Type="RIM DIAMETER">0022.50-"</NameValue>
</Property>
</Specification>
- <Specification Type="PHYSICAL">
- <Property>
<NameValue Type="WIDTH">0000315MM</NameValue>
</Property>
</Specification>
- <Specification type="PHYSICAL">
- <Property>
<NameValue name="HEIGHT WIDTH RATIO" unitCode="XXX">080</NameValue>
</Property>
</Specification>
|
I need to fetch the value
"SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/@type='Physical'
SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/Property/NameValue/@type='WIDTH'"
That means i need to check the Specification type "Physical" then need to get inside to take the property value @type"WIDTH"
I am new to XML parsing I just need an idea. Thanks for all gurus how are helping me here .
is the below code is suffice to fetch the values
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd = THE (SELECT FIELDVALUE(I.Property.*:NameValue.(XML.Attribute)Type= 'WIDTH') AS type
FROM itemMaster.(XMLNSC.Field).*:ItemMasterHeader.*:Specification.*:Description AS I)
WHERE I.Specification = 'PHYSICAL'); |
I refer http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fac67241_.htm
Last edited by ydeonia on Mon Apr 29, 2013 6:35 am; edited 1 time in total |
|
Back to top |
|
 |
ydeonia |
Posted: Mon Apr 29, 2013 1:17 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
|
Back to top |
|
 |
smdavies99 |
Posted: Mon Apr 29, 2013 2:18 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
This
Code: |
<Specification Type="PHYSICAL">
|
Shows that the 'Type' is an attribute to the 'Specification' tag.
With that in mind,
Look at your first select example and your last. How do they differ in structure? _________________ 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 |
|
 |
ydeonia |
Posted: Mon Apr 29, 2013 6:36 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
smdavies99 wrote: |
This
Code: |
<Specification Type="PHYSICAL">
|
Shows that the 'Type' is an attribute to the 'Specification' tag.
With that in mind,
Look at your first select example and your last. How do they differ in structure? |
Sorry for that actually theer so many attributes in the code. Please refer the last exampel I have changed it from BRAND to WIDTH. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 29, 2013 6:43 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
(XML.Attribute) is not the same as (XMLNSC.Attribute). |
|
Back to top |
|
 |
ydeonia |
Posted: Mon Apr 29, 2013 6:57 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
mqjeff wrote: |
(XML.Attribute) is not the same as (XMLNSC.Attribute). |
@mqjeff
then Will the below code will fetch the value of the tyrePatternCd to me /
"SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/@type='Physical'
SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/Property/NameValue/@type='WIDTH'"
Code: |
- <Specification Type="PHYSICAL">
- <Property>
<NameValue Type="WIDTH">0000315MM</NameValue>
</Property>
</Specification> |
Code: |
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyrePatternCd = THE (SELECT FIELDVALUE(I.Property.*:NameValue.(XMLNSC.Attribute)Type= 'WIDTH') AS type
FROM itemMaster.(XMLNSC.Field).*:ItemMasterHeader.*:Specification AS I)
WHERE I.Specification = 'PHYSICAL'); |
Last edited by ydeonia on Mon Apr 29, 2013 7:01 am; edited 1 time in total |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 29, 2013 6:59 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Is "PHYSICAL" the value of the I.Specification element? |
|
Back to top |
|
 |
ydeonia |
Posted: Mon Apr 29, 2013 7:04 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
mqjeff wrote: |
Is "PHYSICAL" the value of the I.Specification element? |
Please see the above comment I have edited it. "PHYSICAL" is the attribute of the Specification . If "type"= "PHYSICAL" then I need to take the value of property.*:NameValue has the "Type" WIDTH. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 29, 2013 7:10 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
ydeonia wrote: |
mqjeff wrote: |
Is "PHYSICAL" the value of the I.Specification element? |
Please see the above comment I have edited it. "PHYSICAL" is the attribute of the Specification . If "type"= "PHYSICAL" then I need to take the value of property.*:NameValue has the "Type" WIDTH. |
You have
Code: |
WHERE I.Specification = 'PHYSICAL'); |
That is matching the FIELDVALUE of I.Specification against the string "PHYSICAL".
You have XML data that has
Code: |
<Specification Type="PHYSICAL"> |
I repeat the question.
Is "Physical" the value of the I.Specification element?
An excellent way to troubleshoot SQL Select statements is to make sure that you are selecting the right things in the first place, by removing all where clauses.
Then when you know you are getting back the right set of data, even if too much of it, then you can add where clauses to troubleshoot those separately. |
|
Back to top |
|
 |
ydeonia |
Posted: Mon Apr 29, 2013 7:15 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
mqjeff wrote: |
That is matching the FIELDVALUE of I.Specification against the string "PHYSICAL".
You have XML data that has
Code: |
<Specification Type="PHYSICAL"> |
I repeat the question.
Is "Physical" the value of the I.Specification element?
. |
Here is the requirement
"SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/@type='Physical'
SyncItemMaster/DataArea/ItemMaster/ItemMasterHeader/Specification/Property/NameValue/@type='WIDTH'"
I have to check if specification type is "Physical" then I have to fetch the value of Property with type "WIDTH" from that tree.
For this requirement I have written that . Is that piece of code is not correct to fetch the value of type WIDTH .Yes, "Physical" is the type of Specification need to check before to take the value of WIDTH because there are lot of other types with specifications in the XML. |
|
Back to top |
|
 |
|