none
This operation would create an incorrectly structured document. RRS feed

  • Question

  • Hi,

    I am trying the following code to create a new XML document but getting the above error.

    could you please help..

    xml_document = new XDocument();
    
    xml_document.Declaration = new XDeclaration("1.0", "utf-8", "true");
    
    xml_document.Add(new XElement("EventLog"));
    XElement event_node = new XElement("Event", new XAttribute("ID", Guid.NewGuid().ToString()));
    XElement event_date = new XElement("DateTime", DateTime.UtcNow.ToString("ddd dd MMM yyyy HH:mm:ss"));
    XElement event_details = new XElement("Description", event_description);
    
    event_node.Add(event_date);
    event_node.Add(event_details);
    
    //append element
    xml_document.Add(event_node);
    
    xml_document.Save("eventlog.xml");                
    


    Thursday, December 19, 2013 9:09 PM

Answers

  • Hi Jassim,

    You cannot add node into XDocument directly, try the following code:

    xml_document.Root.Add(event_node);

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 20, 2013 9:11 AM
    Moderator