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 » Fetching the attribute values from XML

Post new topic  Reply to topic Goto page 1, 2  Next
 Fetching the attribute values from XML « View previous topic :: View next topic » 
Author Message
ydeonia
PostPosted: Sat Apr 27, 2013 2:33 am    Post subject: Fetching the attribute values from XML Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Sat Apr 27, 2013 8:03 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Vitor
PostPosted: Sat Apr 27, 2013 10:08 am    Post subject: Re: Fetching the attribute values from XML Reply with quote

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
View user's profile Send private message
mqsiuser
PostPosted: Sat Apr 27, 2013 12:00 pm    Post subject: Re: Fetching the attribute values from XML Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Sat Apr 27, 2013 2:05 pm    Post subject: Re: Fetching the attribute values from XML Reply with quote

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
View user's profile Send private message
ydeonia
PostPosted: Sat Apr 27, 2013 6:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
ydeonia
PostPosted: Mon Apr 29, 2013 1:17 am    Post subject: Reply with quote

Acolyte

Joined: 29 Oct 2012
Posts: 74

Any idea ?
Back to top
View user's profile Send private message
smdavies99
PostPosted: Mon Apr 29, 2013 2:18 am    Post subject: Reply with quote

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
View user's profile Send private message
ydeonia
PostPosted: Mon Apr 29, 2013 6:36 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Mon Apr 29, 2013 6:43 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

(XML.Attribute) is not the same as (XMLNSC.Attribute).
Back to top
View user's profile Send private message
ydeonia
PostPosted: Mon Apr 29, 2013 6:57 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Mon Apr 29, 2013 6:59 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Is "PHYSICAL" the value of the I.Specification element?
Back to top
View user's profile Send private message
ydeonia
PostPosted: Mon Apr 29, 2013 7:04 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Mon Apr 29, 2013 7:10 am    Post subject: Reply with quote

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
View user's profile Send private message
ydeonia
PostPosted: Mon Apr 29, 2013 7:15 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Fetching the attribute values from XML
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.