Link to home
Start Free TrialLog in
Avatar of hoyaabanks
hoyaabanks

asked on

Creating and Modifying XML Documents

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#.

Example:
=======================
<?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.
</Message>
    <User>john.smith@js.com</User>
    <StackTrace>

[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
</StackTrace>
  </Error>  
</ErrorLog>
Avatar of davecorun
davecorun

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

http://msdn2.microsoft.com/en-us/library/aa480461.aspx

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

ASKER

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.
If you're asking how to properly read / write the XML file, try the XmlDocument or XmlStreamReader class.  Those are your best bets.
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?
ASKER CERTIFIED SOLUTION
Avatar of davecorun
davecorun

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
Forced accept.

Computer101
EE Admin