Best practices for programmatically creating XML storage files
-
I need to programmatically create XML storage files, and I've seen what people do in articles. It seems that most people just use the XmlWriter class, manually writing low-level elements one at a time. However, I was wondering if there's a more elegant way to accomplish this task; for instance, a single function that says: "Make a 'hello' node as the child of 'root'->'greetings'->'hi'" where the 'hello' node is fully defined in a class before being inserted.
-
I need to programmatically create XML storage files, and I've seen what people do in articles. It seems that most people just use the XmlWriter class, manually writing low-level elements one at a time. However, I was wondering if there's a more elegant way to accomplish this task; for instance, a single function that says: "Make a 'hello' node as the child of 'root'->'greetings'->'hi'" where the 'hello' node is fully defined in a class before being inserted.
Use an XmlDocument, fill it, and use .WriteTo ?
-
I need to programmatically create XML storage files, and I've seen what people do in articles. It seems that most people just use the XmlWriter class, manually writing low-level elements one at a time. However, I was wondering if there's a more elegant way to accomplish this task; for instance, a single function that says: "Make a 'hello' node as the child of 'root'->'greetings'->'hi'" where the 'hello' node is fully defined in a class before being inserted.
jesarg wrote:
It seems that most people just use the XmlWriter class, manually writing low-level elements one at a time. However, I was wondering if there's a more elegant way to accomplish this task; for instance, a single function that says: "Make a 'hello' node as the child of 'root'->'greetings'->'hi'" where the 'hello' node is fully defined in a class before being inserted.
Have you looked into Serialization?
System.Xml.XmlSerializer
led mike