Pergunta

I have an xml like

 <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

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

the above code give me result like only one

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

>

How can I iterate the values to get all like

I have tried the While loop but its not working

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

Foi útil?

Solução

This is very simple to achieve. Try below code:

 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. It's good practice to struggle and find solutions at your own, rather than searching for spoon feeding.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top