Author |
Message
|
agrawalamit166 |
Posted: Mon Dec 10, 2012 7:47 am Post subject: move multiple fields |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
Hi
I have
Quote: |
Input message:
<Root>
<core>
<x>a</x>
<y>b</y>
<z>c</z>
</core>
<optional>
<x>d</x>
<y>e</y>
<z>f</z>
<x>g</x>
<y>h</y>
</optional>
</Root> |
I need to convert this message into
Quote: |
Output Message:
<Root>
<core>
<x>a</x>
<y>b</y>
<z>c</z>
<x>d</x>
<y>e</y>
<z>f</z>
<x>g</x>
<y>h</y>
</core>
</Root>
|
The problem, I am facing, is: how to add optional tree at the end of "Core". Optional does not contain same type of records (x,y,z etc...) |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Dec 10, 2012 7:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
In ESQL, you can add these elements using the SET statement. |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Mon Dec 10, 2012 7:57 am Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
I know that but the problem is: if i use set , then it will override the previous element.
If I use CREATE LASTCHILD OF OutputRoot.XMLNSC.Root.Core... then I need to loop it for number of element inside <Optional> |
|
Back to top |
|
 |
Vitor |
Posted: Mon Dec 10, 2012 8:07 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
agrawalamit166 wrote: |
I know that but the problem is: if i use set , then it will override the previous element. |
Not if you use 1 SET statement to build the whole of OutputRoot.XMLNSC.Root.Core, including the bits which exist in the InputRoot already. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Dec 10, 2012 8:08 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Or you can use a SELECT statement.
Or you can not use ESQL and use other methods in other transformation interfaces. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Dec 10, 2012 8:15 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
Or you can use a SELECT statement.
|
In truth, I'd probably do it with a SELECT statement if I actually had to do it.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Mon Dec 10, 2012 8:42 am Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
The problem with SELECT is: how to add two inputs (<core><element> && <optional><element>)
The Actual tree is like:
Quote: |
<Root>
<info>
<core>
<element>
<x><a>Complex tree node</a></x>
<y>Simple tree node</y>
<z><c><a>Complex tree node</a></c></z>
</element>
</core>
<optional>
<element> <x>d</x><y>e</y><z>f</z><x>g</x><y>h</y><z>d</z><x>c</x><y>b</y><z>a</z>
</element>
</optional>
</info>
<info><core><element>
<x>a</x>
<y>b</y>
<z>c</z>
</element>
</core>
<optional>
<element> <x>d</x><y>e</y><z>f</z><x>g</x><y>h</y><z>d</z><x>c</x><y>b</y><z>a</z>
</element>
</optional>
</info>
</Root>
|
I am using following code right now in ESQL:
Code: |
I create the Reference for <info> tag and
WHILE(LASTMOVE(infoRef) AND i < 100) DO
SET outputRef.info[count].core = infoRef.core; ---- i got the outputRef.info[count].core.element with x..y..z.. tags
SET outputRef.info[count].core.element= infoRef.optional.element.*; --- I know this statement is wrong, but want to know how can I put this
SET count = count + 1;
MOVE infoRef NEXTSIBLING REPEAT TYPE NAME;
SET i = i + 1;
END WHILE;
|
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Dec 10, 2012 8:48 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You tell the select statement to select two things from two parts of the input message. |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Mon Dec 10, 2012 9:38 am Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
I use SELECT but it still overriding the core element value:
Code: |
SET outputRef.info[] = (SELECT I.core.element,
I.optional.element FROM InputRef.info[] AS I );
|
|
|
Back to top |
|
 |
mqsiuser |
Posted: Tue Dec 11, 2012 12:57 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
agrawalamit166 wrote: |
I know that but the problem is: if i use set , then it will override the previous element. |
Yes, that is how SET works. And using SET-Statements (when possible) (and with references ) is the usual way you code in ESQL.
agrawalamit166 wrote: |
If I use CREATE LASTCHILD OF OutputRoot.XMLNSC.Root.Core... then I need to loop it for number of element inside <Optional> |
Yes, I would do it like this.
ESQL-SELECT will (either) just do the same thing (internally) (or it does something else: Happy guessing... and if you are lucky it ends up with what you would (just) code yourself. (That's a bit negative... what ESQL-SELECT does is documented properly ofc. somewhere)).
Probably ESQL-SELECT may be faster (since it uses native-c)... so I'd consider using SELECT if I'd have problems with ESQL-Reference-Tree-walking's performance (which is unlikely to happen)).
So I highly recommend that you just write an ESQL-Reference-Loop (with CREATE (LASTCHILD) statements)
You may think... "Ah, I spare time, when I write the SELECT"... but I do not think that this happens: You may be quicker coding a SELECT initially... but you might not be able to adjust it freely and it may not do what you want it to do (you actually confirmed that in your last post) and then you might not bring it to do what you want it to do. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Tue Dec 11, 2012 7:38 am Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
Thanks MqsiUser, for you comments...
I am using Create Last child option. and this is fine for simple tree node.
for example: <x>a</x>
But I am getting issue with complex tree:
Example: <attGroup id="1"> <attr name="Name">AAA</attr><attr name="Address">BBBB</attr></attGroup>
I write this code:
Code: |
DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
SET outputRef.core[count].element.*[<].*[] = optionalAttrRef.*[];
END WHILE;
|
above mentioned code just adds the "ID" attribute but Sub tree are still not associated with AttrGroup node.
Thanks,
Amit |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Tue Dec 11, 2012 7:54 am Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
I got the Solution for this:
Code: |
DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
SET outputRef.core[count].element.*[<] = optionalAttrRef;
END WHILE;
|
Now This is working fine for me. Thanks a lot for your support.... |
|
Back to top |
|
 |
mqsiuser |
Posted: Thu Dec 13, 2012 5:21 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Quote: |
DECLARE optionalAttrRef REFERENCE TO gtinInfoRef.optional.element.*[1];
WHILE(LASTMOVE(optionalAttrRef) AND i < 100) DO
CREATE LASTCHILD OF outputRef.core[count].element NAME FIELDNAME(optionalAttrRef) VALUE optionalAttrRef;
SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
SET outputRef.core[count].element.*[<] = optionalAttrRef;
END WHILE; |
Your ESQL looks as if you could optimize it a bit, though Programmer time is expensive (we are so expensive ) so you just leave it as it is (as long as you don't get into performance issues).
I think the bold parts might / can be optimized:
1. Just use LASTMOVE (it is unlikely that you need integer-variables, like "i" or "count")
2. Accessing elements with long paths (on one line) can also likely be / get replaced with a REFERENCE
3. Accesssing elements with [count] can also usually be avoided.
AND usually you should have a MOVE optionalAttrRef NEXT ... before "END WHILE"
Try to walk along the leaves (of the tree)  _________________ Just use REFERENCEs |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Dec 13, 2012 5:34 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
agrawalamit166 wrote: |
I use SELECT but it still overriding the core element value:
Code: |
SET outputRef.info[] = (SELECT I.core.element,
I.optional.element FROM InputRef.info[] AS I );
|
|
I would have done
Code: |
Set OutputRef.info[] = SELECT I.element, J.element from InputRef.info.core.[] as I, InputRef.optional.[] as J |
I do not say this will work any better, just that it's closer to what I suggested. |
|
Back to top |
|
 |
agrawalamit166 |
Posted: Thu Dec 13, 2012 1:50 pm Post subject: |
|
|
 Voyager
Joined: 17 Aug 2009 Posts: 78 Location: NY, US
|
Code: |
Set OutputRef.info[] = SELECT I.element, J.element from InputRef.info.core.[] as I, InputRef.optional.[] as J
|
I will look into it and update you whether it works for me or not.
Quote: |
1. Just use LASTMOVE (it is unlikely that you need integer-variables, like "i" or "count")
2. Accessing elements with long paths (on one line) can also likely be / get replaced with a REFERENCE
3. Accesssing elements with [count] can also usually be avoided.
AND usually you should have a MOVE optionalAttrRef NEXT ... before "END WHILE"
|
1. We have a requirement to do it till 100 element.
2. I have removed
Code: |
SET outputRef.core[count].element.*[<].(XMLNSC.Attribute)id = optionalAttrRef.(XMLNSC.Attribute)id;
|
Because next line does this task as well
Code: |
SET outputRef.core[count].element.*[<] = optionalAttrRef;
|
3. I will try to avoid count...
obviously i am using MOVE optionalAttrRef NEXTSIBLING; and increamenting "i" and count.
Thanks,
Amit |
|
Back to top |
|
 |
|