2013-05-09 61 views
0

的XML值我有一个像提取循环

<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> 

一个XML我已经写了希望得到的

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[]); 

上面的代码值给出我造成像只有一个

<components> 
<productCd >033144_5423</productCd > 
<quantity>1</quantity> 
</components 

>

我该怎么做ite率的值,以得到像

我试图While循环,但它不是所有工作

<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> 

感谢。

回答

1

这很容易实现。请尝试以下代码:

DECLARE inputRef REFERENCE TO InputRoot.XMLNSC.NS5:CAIAssembly; 

    DECLARE Ref_CAIComponent REFERENCE TO inputRef.NS5:CAIComponent[1]; 

    --Now run the below loop 

     WHILE LASTMOVE(Ref_CAIComponent) DO 

    CREATE FIELD OutputRoot.XMLNSC.components[index]; 
    DECLARE outRef REFERENCE TO OutputRoot.XMLNSC.components[index]; 
    SET index=index+1; 

    SET outRef.productCd=Ref_CAIComponent.NS5:CAICode; 
    SET outRef.quantity=Ref_CAIComponent.NS5:Quantity; 


    MOVE Ref_CAIComponent NEXTSIBLING REPEAT NAME; 
    END WHILE; 

P.S.这是一个很好的做法,可以自己努力寻找解决方案,而不是寻找勺子喂食。

+0

谢谢,但我已经解决了我自己的问题。 :)在同一天 – Yogus 2013-05-10 09:50:41

+0

我在这里有一个问题,你可以请给我你的价值投入http://stackoverflow.com/questions/16479581/lastmove-loop-is-not-working – Yogus 2013-05-10 09:53:46