Author |
Message
|
Chuck831 |
Posted: Sun Oct 09, 2005 10:46 am Post subject: CREATE NEXTSIBLING |
|
|
Apprentice
Joined: 23 Dec 2002 Posts: 28
|
Hello,
I'm trying to create the following XML:
Code: |
<NS1:Data>
<NS1:AcctNo>123</NS1:AcctNo>
<NS1:Addresses>
<Ns2:Addr>
<NS2:Street>123 Main Street</NS2:Street>
<NS2:City>Orlando</NS2:City>
</NS2:Addr>
<Ns2:Addr>
<NS2:Street>3 Union St</NS2:Street>
<NS2:City>Chicago</NS2:City>
</NS2:Addr>
</NS1:Addresses>
<NS1:Data>
|
I have tried using an array subscript and can create the first occurance fine. But when I attempt to create the second occurance I get a subscript out of range exception.
Code: |
Set I = I + 1;
Set OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr[I].NS2:Street = ......
Set OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr[I].NS2:City = ......
|
I have also tried using the CREATE NEXTSIBLING statement:
Code: |
CREATE NEXTSIBLING OF OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr DOMAIN 'XMLNS' NAME 'Addr';
|
There could be 1, 2 or more occurances of the Addr tag. Could someone point me in the right direction.
Thanks.
Chuck |
|
Back to top |
|
 |
jefflowrey |
Posted: Sun Oct 09, 2005 3:55 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Both constructs should work just fine.
We can't tell what's wrong without more context. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
javaforvivek |
Posted: Sun Oct 09, 2005 10:01 pm Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
ANy be you can try with LASTCHILD as well... so many posts on this topic.. the most recent one is by Lilian:
http://www.mqseries.net/phpBB2/viewtopic.php?t=24723 _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
Chuck831 |
Posted: Mon Oct 10, 2005 7:33 am Post subject: |
|
|
Apprentice
Joined: 23 Dec 2002 Posts: 28
|
Let me try to shed more light. After I create the first occurance of <NS2:Addr> I created a procedure to create additional occcurances.
When the I attempt to create the second occurance of <NS2.Addr[2]><NS2:Street> I get an array subscript error. However, if I don't use the procedure it works fine. But I have to create possibly 10 of the same structure and the procedure cuts down on the amount of code.
Any thoughts would be greatly appreciated.
Thanks.
Code: |
Set I = 1;
Set OutputRoot.XMLNS.NS1:Data.NS1.Addresses.NS2.Addr[I].NS2:Street =....
Set OutputRoot.XMLNS.NS1:Data.NS1.Addresses.NS2.Addr[I].NS2:City =....
If InputBody.CustomerData.BillingAddr = 'Y' Then
CREATE NEXTSIBLING OF OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr DOMAIN 'XMLNS' NAME 'Addr';
Set TmpField = ......
Set TmpAttribValue = ......
CALL CreateCustomAttribute(TmpField, TmpAttribValue, I);
End If;
If InputBody.CustomerData.Office = 'Y' Then
CREATE NEXTSIBLING OF OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr DOMAIN 'XMLNS' NAME 'Addr';
Set TmpField = ......
Set TmpAttribValue = ......
CALL CreateCustomAttribute(TmpField, TmpAttribValue, I);
End If;
END;
CREATE PROCEDURE CreateCustomAttribute(IN TmpField Char, IN TmpAttribValue Char, INOUT I INTEGER)
BEGIN
Set I = I + 1;
Set OutputRoot.XMLNS.NS1:Data.NS1.Addresses.NS2.Addr[I].NS2:Street =....
Set OutputRoot.XMLNS.NS1:Data.NS1.Addresses.NS2.Addr[I].NS2:City =....
END;
END MODULE;
|
|
|
Back to top |
|
 |
JT |
Posted: Mon Oct 10, 2005 8:49 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
In the called procedure you're establishing the repeating occurrences through the SET command, so element the CREATE NEXTSIBLING statements and see if you get the results you expect. |
|
Back to top |
|
 |
Chuck831 |
Posted: Mon Oct 10, 2005 10:02 am Post subject: |
|
|
Apprentice
Joined: 23 Dec 2002 Posts: 28
|
JT
I don't understand what you mean by "ELEMENT" the CREATE NEXTSIBLING statement. |
|
Back to top |
|
 |
JT |
Posted: Mon Oct 10, 2005 10:28 am Post subject: |
|
|
Padawan
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
|
Sorry, a typo. I had 'XML element' on my mind.
It should read:
Quote: |
so eliminate the CREATE NEXTSIBLING statements and see if you get the results you expect. |
|
|
Back to top |
|
 |
mgk |
Posted: Mon Oct 10, 2005 1:59 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
You may have a typo in your posting, but your code was so heavily cropped I cannot be sure. However, you start by coding:
CREATE NEXTSIBLING OF OutputRoot.XMLNS.NS1:Data.NS1:Addresses.NS2:Addr DOMAIN 'XMLNS' NAME 'Addr';
Note NS2:Addr which is an element called Addr in the namepace NS2. Also note that the DOMAIN clause here is definately NOT needed and could be harmful used in this context.
That aside, inside your procedure, you reference:
Set OutputRoot.XMLNS.NS1:Data.NS1.Addresses.NS2.Addr[I].NS2:Street
Note the period (.) between NS2 and Addr. This will create an element called NS2 and then create an element Addr inside it then index the i'th occurence which will not exist, so hence the exception. The period should be a colon (
If this is simply a typo when you posted the message then make sure you are not incrementing I once before your procedure call and again inside it (and missing an element in the process) as this could also give you this problem as you increment I at the top of the procedure, and you may actually only want to increment it at the end.
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|