【问题标题】:extract the xml values in loop在循环中提取xml值
【发布时间】:2013-05-10 17:49:20
【问题描述】:

我有一个类似的 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>

我写过想要得到的值

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

>

我怎样才能迭代这些值来得到所有的喜欢

我尝试了 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>

谢谢大家。

【问题讨论】:

    标签: ibm-mq messagebroker


    【解决方案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.最好自己努力寻找解决方案,而不是寻找勺子喂食。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多