tags:

views:

126

answers:

3
XmlElement updateRecipient = doc.CreateElement("UpdateRecipient");
                XmlElement email = doc.CreateElement("EMAIL");
                XmlElement listID = doc.CreateElement("LIST_ID");
                XmlElement column = doc.CreateElement("COLUMN");
                XmlElement name = doc.CreateElement("NAME");
                XmlElement value = doc.CreateElement("VALUE")

                root.AppendChild(body);
                body.AppendChild(updateRecipient);
                updateRecipient.AppendChild(listID);
                listID.InnerText = _listID;
                updateRecipient.AppendChild(email);
                email.InnerText = _email;
                updateRecipient.AppendChild(column);
                column.AppendChild(name);
                name.InnerText = _columnNameFrequency;
                column.AppendChild(value);
                value.InnerText = _actionID.ToString();
                updateRecipient.AppendChild(column);
                column.AppendChild(name);
                name.InnerText = _columnNameStatus;
                column.AppendChild(value);

for some reason, I end up getting only one sub column instead of two under updateRecipient Element. I need both to show up under UpdateRecipient Node like this:

<UpdateRecipient>
<LIST_ID>85628</LIST_ID>
<EMAIL>[email protected]</EMAIL>
<COLUMN>
<NAME>Frequency</NAME>
<VALUE>1</VALUE>
</COLUMN>
<COLUMN>
<NAME>Status</NAME>
<VALUE>Opted In</VALUE>
</COLUMN>
</UpdateRecipient>

but so far I am getting only one :

<UpdateRecipient>
<LIST_ID>85628</LIST_ID>
<EMAIL>[email protected]</EMAIL>
<COLUMN>
<NAME>Status</NAME>
<VALUE>Opted In</VALUE>
</COLUMN>
</UpdateRecipient>

When it hits the first AppendChild(column) and then name and value, frequency shows find but then is later overrident by the Status and I want it to just append a new under and I'mnot sure why it's overriding rather than adding another tag.

A: 

I don't know, but try doing it in the opposite order. That's what I've always done. Don't append updateRecipient to the root, until you're through with it.

John Saunders
+4  A: 

The problem is that you are reusing the "column", "name", & "value" variables. You need to create new XmlElements for the 2nd set.

David
My guess is that you hit the nail on the head.
Cerebrus
That's it: calling AppendChild again with the same object removes the node from the old location and puts it in the new.
Richard
A: 

Thought you could reuse an existing element over again but you can't..