what is the best way to update an XML node value in C#?

My function iterates through every node of an instance of an XMLDocument. It checks to see if the current node's name is in a lookup list. If it is, it applies appropriate validation to the value of the current node.

When the validation method indicates that the value has been changed, I want to replace the value in the original document with the updated value.

I think the easiest way to achieve this might be to write out to an XMLTextWriter as I process each node in the original XMLDocument, either writing out the original or modified node and value as appropriate. This method would rely on determining whether the current node has any children, or is a stand-alone node.

Is there a better way I could update the values in the original document? I need to end up with the complete XMLDocument, but with updated node values, where appropriate.

Thanks in advance.

Answers


Can you not modify the existing nodes (which ate already in the correct structure and in an XMLDocument, then re-serialise the XMLDocument? If the nodes are simple text containters then the

.InnerText

property is the one you want.


I know I always go back to this but this sounds like an example where clever use of apply-templates and ExtensionObjects in XSLT would be efficient.

That said XMLDocument is optimised for modification, so if you were going with a pure programmatic solution I would modify the object directly, not create a new Writer.


Need Your Help

How can I update UI when Observable.Context is not available?

system.reactive

I have a WinFrom App, use synchronous method to download string from a url, and use Rx ToAsync Method to make it asynchronous and get the observable result, and when the result comes I show it on the

wordpress mysql - delete all custom post type

mysql sql database wordpress

I've got a wordpress/mysql set up using the 'custom post type' which currently holds about 40,000 rows of data in the wp_posts table of the database. I'm trying to work on an SQL query that will ...