2013-05-09 59 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