Hi all, great community!
Let's say I have the following XML document that I want tofollow:
<CallLogs>
<Call>
<Data>
<SubEntry></SubEntry>
<SubEntry></SubEntry>
<SubEntry></SubEntry>
</Data>
</Call>
</CallLogs>
I have an XML writer that will append all the elements and nodes<Call> through </Call> between the <CallLogs> elements. This isdone so that if the file already exists, it will just append tothe current file, without overwriting. This works just dandy. here comes my problem though. The data that goes into a<SubEntry></SubEntry> node is from a dataset. So I will have aline of code that looks like this to create my nodes of text:
XmlText textNode1 =xmlDoc.CreateTextNode(ds.Tables[0].Rows[0][0].ToString());
These text nodes get applied into my schema as follows:
call.AppendChild(data);
data.AppendChild(subEntry1);
subEntry0.AppendChild(textNode1);
I have found from trial and error that the elements must haveunique names (correct?) For instance, if I try the followingcode:
call.AppendChild(data);
data.AppendChild(subEntry1);
subEntry0.AppendChild(textNode1);
call.AppendChild(data);
data.AppendChild(subEntry1);
subEntry0.AppendChild(textNode2);
it will overwrite the previously written node. Makes sense.
What I want to do is dynamically create the subEntry XmlElementsso that I can add accordingly to how many rows are in thedataset. I can't find an optimal method to do so. I would liketo create a new
XmlElement subEntry[i] = xmlDoc.CreateElement("SubEntry");
where i is in accordance to the row count of the dataset. I needto then do the same with the textNodes:
XmlText textNode[i] =xmlDoc.CreateTextNode(ds.Tables[0].Rows[i][0].ToString());
again where i is in accordance to the row count. Is there a wayto make an array of XmlElements or XmlNodes, iterate throughthat array accordingly? Then i can just create the elements andcall the ones that will associate with the row number beingused.
I appreciate any help possible with this.
User submitted from AEWNET (http://www.aewnet.com/)