Home All Groups Group Topic Archive Search About

Xml appending child nodes

Author
11 Apr 2005 5:52 PM
hharry
Hi All,

If I have the following xml:

<Response>
    <AddressDetails>
        <Address>
        </Address>
    </AddressDetails>
</Response>

and I need to insert multiple address records like this:

<Response>
    <AddressDetails>
        <Address>
            <City></City>
            <State></State>
        </Address>
        <Address>
            <City></City>
            <State></State>
        </Address>
    </AddressDetails>
</Response>

I have used the xmlnode.appendchild method to do this, but I can only
add one address, the original address is replaced so i end up with only
1 address like this:

<Response>
    <AddressDetails>
        <Address>
            <City></City>
            <State></State>
        </Address>
    </AddressDetails>
</Response>

Thanks in advance

Author
11 Apr 2005 10:05 PM
Marcie Jones
Hi,
You'll need to also append another Address node to AddressDetails.

Marcie

Show quoteHide quote
On 11 Apr 2005 10:52:54 -0700, "hharry" <paulquig***@nyc.com> wrote:

>Hi All,
>
>If I have the following xml:
>
><Response>
>    <AddressDetails>
>        <Address>
>        </Address>
>    </AddressDetails>
></Response>
>
>and I need to insert multiple address records like this:
>
><Response>
>    <AddressDetails>
>        <Address>
>            <City></City>
>            <State></State>
>        </Address>
>        <Address>
>            <City></City>
>            <State></State>
>        </Address>
>    </AddressDetails>
></Response>
>
>I have used the xmlnode.appendchild method to do this, but I can only
>add one address, the original address is replaced so i end up with only
>1 address like this:
>
><Response>
>    <AddressDetails>
>        <Address>
>            <City></City>
>            <State></State>
>        </Address>
>    </AddressDetails>
></Response>
>
>Thanks in advance
Author
12 Apr 2005 1:36 PM
Chris Dunaway
I'm not sure what you're project is doing, but one alternative is to
create a class that models your entire XML structure and add the
Serializable attribute to it.  Then you can just serialize and
deserialize directly to XML without having to deal with the xml
yourself.
Author
12 Apr 2005 2:35 PM
hharry
Chris Dunaway wrote:
> I'm not sure what you're project is doing, but one alternative is to
> create a class that models your entire XML structure and add the
> Serializable attribute to it.  Then you can just serialize and
> deserialize directly to XML without having to deal with the xml
> yourself.

Thanks for the pointers. I needed to declare a new set of xml nodes for
each child group!