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.InvalidO perationEx ception">
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</U ser>
<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.g et_Selecte dDataKey() +1500582
System.Web.UI.WebControls. GridView.g et_Selecte dValue() +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.Refl ectPropert yDescripto r.GetValue (Object component) +370
System.Web.UI.DataBinder.G etProperty Value(Obje ct container, String propName) +77
System.Web.UI.DataBinder.E val(Object container, String[] expressionParts) +79
System.Web.UI.DataBinder.E val(Object container, String expression) +108
System.Web.UI.WebControls. ControlPar ameter.Eva luate(Http Context context, Control control) +310
System.Web.UI.WebControls. Parameter. UpdateValu e(HttpCont ext context, Control control) +46
System.Web.UI.WebControls. ParameterC ollection. UpdateValu es(HttpCon text context, Control control) +103
System.Web.UI.WebControls. ObjectData Source.Loa dCompleteE ventHandle r(Object sender, EventArgs e) +40
System.EventHandler.Invoke (Object sender, EventArgs e) +0
System.Web.UI.Page.OnLoadC omplete(Ev entArgs e) +2058120
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +1209
</StackTrace>
</Error>
</ErrorLog>
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.InvalidO
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</U
<StackTrace>
[InvalidOperationException
System.Web.UI.WebControls.
System.Web.UI.WebControls.
[TargetInvocationException
System.ComponentModel.Refl
System.Web.UI.DataBinder.G
System.Web.UI.DataBinder.E
System.Web.UI.DataBinder.E
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.EventHandler.Invoke
System.Web.UI.Page.OnLoadC
System.Web.UI.Page.Process
</StackTrace>
</Error>
</ErrorLog>
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
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.