Write xmldocument to file




















Download Microsoft Edge More info. Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No. Any additional feedback? Submit and view feedback for This product This page.

White space is preserved only if PreserveWhitespace is set to true. The XmlDeclaration of the current XmlDocument object determines the encoding attribute in the saved document.

The value of the encoding attribute is taken from the XmlDeclaration. Encoding property. If the XmlDocument does not have an XmlDeclaration, or if the XmlDeclaration does not have an encoding attribute, the saved document will not have one either.

For example, the following C code. Note that only the Save method enforces a well-formed XML document. All other Save overloads only guarantee a well-formed fragment. The encoding on the TextWriter determines the encoding that is written out The encoding of the XmlDeclaration node is replaced by the encoding of the TextWriter.

If there was no encoding specified on the TextWriter , the XmlDocument is saved without an encoding attribute. The following example loads XML into an XmlDocument object, modifies it, and then saves it to a file named data. The data. White space is preserved in the output file only if PreserveWhitespace is set to true. Add a comment. WriteAllText "myFile. BFree BFree For serialization or non-namespaced Xml this approach is more efficient.

Anton Gogolev Anton Gogolev k 37 37 gold badges silver badges bronze badges. I know you said C but have you tried VB. Amazing stuff. WriteLine myXML. ToString myXML. Save ". Mike Bonnell Mike Bonnell 7 7 bronze badges.

This is not a case of the right tool for the job. Your post is an example of the limitations of only knowing one tool and trying to force everything into it. No My post in an example of what an open mind can do by using projects of more than one language in the same solution. I use both VB and C. It is unclear how much "everything else" is done in C by pragadheesh.

Perhaps he explores alternatives. I still say introducing another language for the simple purpose of saving an XML string is ridiculous.

Actually open your mind and think about what you're proposing: "Gee, I'll bring in a bulldozer, even though all I need is a trowel, to move this cup full of sand into the garden. Sign up or log in Sign up using Google.



0コメント

  • 1000 / 1000