IIB中的ESQL XML创建

时间:2017-01-16 05:23:00

标签: messagebroker ibm-integration-bus extended-sql

有人可以帮我在IIB中使用ESQL创建下面的xml结构

输入:

<animal>
     <animaldomestic>dog<animaldomestic>
     <animalwild>cheetah<animalwild>
</animal>

输出:

<animals>
  <animal type="domestic">cow</animal>
  <animal type="wild">cheetah</animal>
</animals>

4 个答案:

答案 0 :(得分:4)

SET OuputRoot.XMLNSC.animals。(XMLNSC.Attribute)animal =&#39; domestic&#39 ;; SET OutputRoot.XMLNSC.animals.animal =&#39; cow&#39;;

SET OuputRoot.XMLNSC.animals。(XMLNSC.Attribute)animal =&#39; wild&#39 ;; SET OutputRoot.XMLNSC.animals.animal =&#39; cheetah&#39;;

答案 1 :(得分:1)

我为此找到了解决方案。请找到以下代码:

SET OutputRoot.XMLNSC.animals.animal[1].(XMLNSC.Attribute)type = 'domestic';
SET OutputRoot.XMLNSC.animals.animal[1]VALUE = InputRoot.XMLNSC.animal.animaldomestic;
SET OutputRoot.XMLNSC.animals.animal[2].(XMLNSC.Attribute)type = 'wild';
SET OutputRoot.XMLNSC.animals.animal[2]VALUE = InputRoot.XMLNSC.animal.animalwild;

答案 2 :(得分:1)

如果你想要通用代码:

DECLARE animal REFERENCE TO InputRoot.XMLNSC.animal.*[>];
DECLARE type CHAR;
DECLARE I INTEGER 1;
WHILE LASTMOVE(animal) DO
    SET type = SUBSTRING(FIELDNAME(animal) AFTER 'animal');
    SET OutputRoot.XMLNSC.animals.animal[I] = FIELDVALUE(animal);
    SET OutputRoot.XMLNSC.animals.animal[I].(XMLNSC.Attribute)type = type;
    SET I = I + 1;
    SET type = '';
    MOVE animal NEXTSIBLING; 
END WHILE;

答案 3 :(得分:0)

@Egorka_nazarov的解决方案是最好的。不过,可以进行一些改进:

    FOR refAnimals AS InputRoot.XMLNSC.animal.*[];
      CREATE LASTCHILD OF OutputRoot.XMLNSC.animals 
        AS refNewAnimal
        TYPE NameValue 
        NAME 'animal' 
        VALUE FIELDVALUE(refAnimals);

      DECLARE type CHARACTER SUBSTRING(FIELDNAME(refAnimals) AFTER 'animal');
      SET refNewAnimal.(XMLNSC.Attribute)type = type;
    END FOR;

上面的代码更短,更不可能包含错误(显然,一旦您使用REFERENCE变量进行了练习)。