Author |
Message
|
theone |
Posted: Mon Feb 05, 2007 4:57 am Post subject: Build XML tree dynamically |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Hi,
I need to build XML tree at runtime.
For example:
The xml path to create is a.b.c (known at runtime only) and the value should be taken from InputRoot.XML.c.d (c.d known at runtime).
The result should be:
Code: |
<a>
<b>
<c>..</c>
</b>
</a> |
Any idea how to do that? |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Feb 05, 2007 5:03 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Yes.
This is basic use of the product. You can do this with ESQL SET statements.
The Info Center has a specific section on how to address fields dynamically and another section on how to address fields anonymously in ESQL.
Also, please use the XMLNS or XMLNSC domain, and not the XML domain. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 5:23 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Using anonymous field references let me refer to the array of children, and accessing fields dynamically let me navigate the tree using a reference. I don’t see how it can help me achieving my request. Remember that I don’t know which field I need to access and from where to take the value at build time.
How do I create a sub tree at run time? If I get the path as a runtime parameter, how do I then create it under Outputroot.XMLNS?
Lets say I get a Message:
<Root>
<First>
<Second>second</Second>
</First>
</Root>
In a db I have a column source and target (similar to mapping node, but dynamic).
Source = Root.First.Second
Target = Root.Second
I need to then create a message:
<Root>
<Second>second</Second>
</Root>
Hope it explains my requirements properly.
Thanks |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 05, 2007 5:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
theone wrote: |
Remember that I don’t know which field I need to access and from where to take the value at build time.
|
That's why they're called dynamic....
This is fairly straightforward stuff. You're just trying to create a sub-tree based on a pattern retrieved from a database.
I'll not comment on the wisdom of doing it. You know your requirements best. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Feb 05, 2007 5:38 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay. So you have a path in the database, that is an ESQL path.
Ideally, one would like to just use {} to evaluate the variable that holds that path.
You can't, though, as {} only supports a single level (one dot).
Everything else in your question is just using the SET command.
You can also look at using XPath - but you'll likely want to do that from Java instead of ESQL, as you'd have to write at least some Java to evaluate XPath anyway. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 5:44 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Hi,
It is dynamic in the sense that you can navigate the tree without the need to know the field name.
However, in my case the field name is known at runtime. I don’t want to go over the xml tree and compare the field name of each element to the value from db.
I want to take the target value from the db and evaluate it in such way that it will create the sub tree.
I tried something like:
DECLARE path CHARACTER ‘a.b’;
SET OutputRoot.XML.{path} = ‘aaa’;
The result of it was a field called a.b.
Please comment on the wisdom of doing it. I may learn something new |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Feb 05, 2007 5:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
jefflowrey wrote: |
{} only supports a single level (one dot). |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 5:49 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
I posted my reply before I seen your response
So based on what you say, I cannot do it in ESQL?
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Feb 05, 2007 5:56 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
No.
You can do it in ESQL. You just have to evaluate the path one dot at a time. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 6:01 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Well, yes. I really don’t like it  |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Feb 05, 2007 6:06 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I agree that it would be nice if one could use XPath from ESQL without having to write at least some Java.
But it's not a *lot* of Java that one has to write, nor entirely difficult. A static procedure will do the trick. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 05, 2007 6:10 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
theone wrote: |
Well, yes. I really don’t like it  |
Life is filled with injustice. We must all try the best we can to make the world a better place.
Or simply keep our heads down and work out which is the easiest / less stressful way of achieving a goal. This choice now faces you. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 6:10 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Sure.
Thanks for your help |
|
Back to top |
|
 |
theone |
Posted: Mon Feb 05, 2007 6:14 am Post subject: |
|
|
Novice
Joined: 04 Dec 2006 Posts: 15
|
Vitor,
Just think something so trivial should be supported by ESQL. However, I always love doing Java coding  |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 05, 2007 6:17 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
theone wrote: |
Just think something so trivial should be supported by ESQL. However, I always love doing Java coding  |
Be glad you have v6 and access to Java. Some of us are condemed to remain on v2.1 for a few months longer.
I love Java coding too. I can watch the Java developers doing it for hours, longer if someone's bringing me coffee....  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|