Creating and Modifying XML Documents

Posted on 2007-08-12
Last Modified: 2013-11-26
I am creating custom error logging using an XML document that looks like the example below.  What is the best way to create logic to edit this file, so that when a new error occures I can quickley and effortlsly write it to an error log file in some reusable way.

I am using ASP.NET and C#.

<?xml version="1.0" encoding="utf-8" ?>
<ErrorLog Date="03/04/07">
  <Error Time="04:20:00">
    <Message Exception="System.InvalidOperationException">
         Data keys must be specified on GridView 'gvCategories' before the selected data keys can be retrieved.  Use the DataKeyNames property to specify data keys.

[InvalidOperationException: Data keys must be specified on GridView 'gvCategories' before the selected data keys can be retrieved.  Use the DataKeyNames property to specify data keys.]
   System.Web.UI.WebControls.GridView.get_SelectedDataKey() +1500582
   System.Web.UI.WebControls.GridView.get_SelectedValue() +12

[TargetInvocationException: Property accessor 'SelectedValue' on object 'System.Web.UI.WebControls.GridView' threw the following exception:'Data keys must be specified on GridView 'gvCategories' before the selected data keys can be retrieved.  Use the DataKeyNames property to specify data keys.']
   System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +370
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +77
   System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts) +79
   System.Web.UI.DataBinder.Eval(Object container, String expression) +108
   System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +310
   System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +46
   System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +103
   System.Web.UI.WebControls.ObjectDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +40
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnLoadComplete(EventArgs e) +2058120
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1209
Question by:hoyaabanks
    LVL 8

    Expert Comment

    I use the Enterprise Library extensively, and there is an Exception Handling Application Block which represents most of the best practices for Exception Handling.

    Definitely worth a look.  You can specify policies, which it seems is exactly what you're describing.

    Author Comment

    The more important part of this question is best practices for creating and manipulation XML documents.  This XML exception handling system is a requirement for the project I am on, because that is how we drive the data to flash.
    LVL 8

    Expert Comment

    If you're asking how to properly read / write the XML file, try the XmlDocument or XmlStreamReader class.  Those are your best bets.

    Author Comment

    Do you have a good example of tutorail, or a couple of lines of code that show you how to access and write independent nodes using those objects?
    LVL 8

    Accepted Solution

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now