Click to See Complete Forum and Search --> : XmlDocument XmlNode::ReplaceChild confusion


WhyDoesItNotWork...:-(
July 23rd, 2004, 07:27 AM
Hi,

I seem to be missing the boat a bit here. I am trying to iterate over XmlNodes and replace, example code as follows:

void XmlM::updateRecord(void)
{
// recordEnum is an enumerator of nodes directly under the root
XmlNode * parentNode = dynamic_cast<XmlNode*>(recordEnum->Current);
childEnum = parentNode->ChildNodes->getEnumerator();

childEnum->moveNext();

// document is instance of XmlDocument
XmlNode * entry = document->CreateElement(S"", S"connumber", "");
//get text from form
entry->InnerText = txtConnum->text;
parentNode->ReplaceChild(entry, dynamic_cast<XmlNode*>(childEnum->current)):

// the above is repeated for each field until:

document->Save(S"C:\\test.xml);

// which doesn't seem to work either

This compiles but I get InvalidOperationExceptions thrown when I go beyond the first field. When I stick to the first field and call document->Save(); it clearly does not.

Any suggestions? I get the feeling I've completely missed the point somehow.

Thanks

-Y