开发者

Rollbacking changes in XML Document

开发者 https://www.devze.com 2022-12-14 13:47 出处:网络
I Want to raise an event to prevent any modification on the Xml file. Simply raising an event is enough ? like

I Want to raise an event to prevent any modification on the Xml file.

Simply raising an event is enough ? like

XElement doc = XElement.Load(@"d:\XMLFiles\namespace.xml");
doc.Changed +=new EventHandler<XObjectChangeEventArgs>(doc_Changed);

What is the code do i need to write inside doc_changed(..,...) to rollback any modifications?

    static void doc_Chang开发者_如何学编程ed(object sender, XObjectChangeEventArgs e)
    {

        //what is the code needed here..?  

    }


Rather than subscribing to Changed, you should subscribe to Changing so that you get notified before it happens.

The easiest way to prevent the change is to throw an exception... but that's quite a severe way of handling it. What situation are you really trying to prevent? Accidental changes due to a developer not understanding that this document is meant to be read-only?

0

精彩评论

暂无评论...
验证码 换一张
取 消