Author |
Message
|
ydeonia |
Posted: Wed May 08, 2013 11:06 pm Post subject: extract the xml values in loop |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Hi
I have an xml like
Code: |
<NS5:CAIAssembly>
<NS5:CAIComponent >
<NS5:CAICode>033144</NS5:CAICode>
<NS5:Quantity>1</NS5:Quantity>
</NS5:CAIComponent>
<NS5:CAIComponent >
<NS5:CAICode>048429</NS5:CAICode>
<NS5:Quantity>1</NS5:Quantity>
</NS5:CAIComponent>
<NS5:CAIComponent >
<NS5:CAICode>073528</NS5:CAICode>
<NS5:Quantity>1</NS5:Quantity>
</NS5:CAIComponent>
<NS5:CAIComponent >
<NS5:CAICode>563781</NS5:CAICode>
<NS5:Quantity>1</NS5:Quantity>
</NS5:CAIComponent>
</NS5:CAIAssembly> |
I have written like to get the values of
Code: |
DECLARE LineCount INTEGER 1;
DECLARE rResource REFERENCE TO orgObj.*:CAIAssembly.*:CAIComponent[1];
WHILE LASTMOVE(rResource) = TRUE DO
SET OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components[LineCount].productCd = COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CAICode[1]),'0')||'_'||COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CCIDCode[1]),'0');
SET OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components[LineCount].quantity = FIELDVALUE(orgObj.*:CAIAssembly.*:CAIComponent.*:Quantity[1]);
SET LineCount = LineCount + 1;
MOVE rResource NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
|
the above code give me result like only one
Code: |
<components>
<productCd>033144_798</productCd>
<quantity>1</quantity>
</components>
<components>
<productCd>033144_798</productCd>
<quantity>1</quantity>
</components>
<components>
<productCd>033144_798</productCd>
<quantity>1</quantity>
</components>
<components>
<productCd>033144_798</productCd>
<quantity>1</quantity>
</components> |
My ProductCd values are not iterating . Please help me to iterate the productCD values too. It should come like below pattern
Code: |
<components>
<productCd >033144_5423</productCd >
<quantity>1</quantity>
</components>
<components>
<productCd >048429_5423</productCd >
<quantity>1</quantity>
</components>
<components>
<productCd >073528_5423</productCd >
<quantity>1</quantity>
</components>
<components>
<productCd >563781_5423</productCd >
<quantity>1</quantity>
</components> |
Thanks all.
Last edited by ydeonia on Thu May 09, 2013 1:00 am; edited 2 times in total |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed May 08, 2013 11:16 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Look at using References and a WHILE LASTMOVE(...) type
something like this
Code: |
declare rResource REFERENCE to inRef.Resource;
while lastmove(rResource) = true do
-- do lots of good stuff here
move rResource nextsibling repeat type name;
end while;
|
_________________ 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: Wed May 08, 2013 11:27 pm Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
smdavies99 wrote: |
Look at using References and a WHILE LASTMOVE(...) type
something like this
Code: |
declare rResource REFERENCE to inRef.Resource;
while lastmove(rResource) = true do
-- do lots of good stuff here
move rResource nextsibling repeat type name;
end while;
|
|
Thanks
You mean to say
Code: |
DECLARE rResource REFERENCE TO orgObj.*:CAIAssembly.*:CAIComponent[1];
WHILE LASTMOVE(rResource) = TRUE DO
SET OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components.productCd = COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CAICode),'0')||'_'||COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CCIDCode),'0');
SET OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components.quantity = FIELDVALUE(orgObj.*:CAIAssembly.*:CAIComponent.*:Quantity);
MOVE rResource NEXTSIBLING REPEAT TYPE NAME;
END WHILE; |
Same output . Didnt worked |
|
Back to top |
|
 |
kash3338 |
Posted: Thu May 09, 2013 1:13 am Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
ydeonia wrote: |
Code: |
OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components.productCd = COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CAICode),'0')||'_'||COALESCE(FIELDVALUE(orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent.*:CCIDCode),'0');
SET OutputRoot.XMLNSC.root.row[rowCnt].Kit_info.components.quantity = FIELDVALUE(orgObj.*:CAIAssembly.*:CAIComponent.*:Quantity);
MOVE rResource NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
|
|
Use rResource whiole doing the mapping. You are actually having a reference rResource and moving it to the next element, but while mapping you are always taking the first element from you input tree.
These two seem to be different,
Code: |
orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent
|
and
Code: |
DECLARE rResource REFERENCE TO orgObj.*:CAIAssembly.*:CAIComponent[1];
|
|
|
Back to top |
|
 |
ydeonia |
Posted: Thu May 09, 2013 1:18 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
kash3338 wrote: |
Use rResource whiole doing the mapping. You are actually having a reference rResource and moving it to the next element, but while mapping you are always taking the first element from you input tree.
These two seem to be different,
Code: |
orgObj.*:ListOfCAD.*:CAD.*:CADAssembly.*:CADComponent
|
and
Code: |
DECLARE rResource REFERENCE TO orgObj.*:CAIAssembly.*:CAIComponent[1];
|
|
Bu when i take
Code: |
DECLARE rResource REFERENCE TO orgObj.*:CAIAssembly.*:CAIComponent[]; |
its gives error.
what should I change here to get values as now I am getting same. |
|
Back to top |
|
 |
ydeonia |
Posted: Thu May 09, 2013 2:00 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Thanks issue is solved. I need to iterate the tree not the value. Thanks all |
|
Back to top |
|
 |
|