Link to home
Start Free TrialLog in
Avatar of rxraza
rxraza

asked on

cannot append to the XML node.

Hi folks:

I am having the following error out of the third line.

System.InvalidOperationException: The current node cannot contain other nodes.

XmlNode appt = CreateParameter("XML_DATA","",false,"");
appt.AppendChild(CreateNode("APPOINT_REQUEST"));
appt.FirstChild.AppendChild(CreateNode("FAMILYNO",familyNo,false));

Can't I just append to the first child of the node that I already appended. Any ideas????

Following are the definition of other functions used:


protected XmlElement CreateNode(string elementName)
{
  XmlElement node = doc.CreateElement(elementName);
  return node;
}

protected XmlElement CreateNode(string elementName,string elementValue,bool isCDATA)
{
 XmlElement node = doc.CreateElement(elementName);
                  
 // create a CDATA elemetn in here
 if (isCDATA )
 {
  XmlCDataSection cDATA = doc.CreateCDataSection(elementValue);
  node.AppendChild(cDATA);
 }
 else
  node.InnerText = elementValue;
 return node;
}


protected XmlElement CreateParameter(string name,string data,bool isCDATA,string type)
{
 XmlElement node = doc.CreateElement("PARAM");
            
 XmlAttribute attribute      = doc.CreateAttribute("NAME");
 attribute.InnerText            = name;
 node.Attributes.Append(attribute);

 attribute  = doc.CreateAttribute("TYPE");
 attribute.InnerText = type;
 node.Attributes.Append(attribute);
 
 if (isCDATA)
 {
   XmlCDataSection cDATA = doc.CreateCDataSection(data);
  node.AppendChild(cDATA);      
 }
 else
 {
  node.InnerText = data;      
 }
      
 return node;
}


ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial