Questions tagged [xmltextwriter]

Represents a writer that provides a fast, non-cached, forward-only way of generating streams

Represents a writer that provides a fast, non-cached, forward-only way of generating streams or files containing XML data that conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

http://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter%28v=vs.110%29.aspx

120 questions
32
votes
3 answers

INSERT XML into SQL Server 2008 database

Hello I'm trying to insert some XML data into a table on SQL Server 2008. However I keep getting thrown this error; XML parsing: line 1, character 39, unable to switch the encoding The database column filemeta uses the XML datatype, and I've…
wonea
  • 4,783
  • 17
  • 86
  • 139
29
votes
1 answer

What is the difference between XmlTextWriter and XmlWriter?

I am looking at these these two classes in C#: XmlTextWriter and XmlWriter. Can anyone explain the difference and tell me where to use which?
Muhammad Basit
  • 291
  • 1
  • 3
  • 3
22
votes
4 answers

Modify XML existing content in C#

Purpose: I plan to Create a XML file with XmlTextWriter and Modify/Update some Existing Content with XmlNode SelectSingleNode(), node.ChildNode[?].InnerText = someting, etc. After I created the XML file with XmlTextWriter as below. XmlTextWriter…
Nano HE
  • 9,109
  • 31
  • 97
  • 137
20
votes
2 answers

How do I set the Settings property in XmlTextWriter, so that I can write each XML attribute on its own line?

I have this bit of code, which serializes an object to a file. I'm trying to get each XML attribute to output on a separate line. The code looks like this: public static void ToXMLFile(Object obj, string filePath) { XmlSerializer serializer =…
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
15
votes
3 answers

XmlTextWriter incorrectly writing control characters

.NET's XmlTextWriter creates invalid xml files. In XML, some control characters are allowed, like 'horizontal tab' ( ), but others are not, like 'vertical tab' ( ). (See spec.) I have a string which contains a UTF-8 control character that is…
Tom Lokhorst
  • 13,658
  • 5
  • 55
  • 71
11
votes
1 answer

Clear all content in XmlTextWriter and StringWriter

I want to clear all of content in XmlTextWriter and StringWriter. Flush() didn't work out. XmlDocument doc = new XmlDocument(); StringWriter sw = new StringWriter(); XmlTextWriter xw = new…
sdeligoz
  • 111
  • 2
  • 6
9
votes
2 answers

xdocument save preserve white space inside tags

I am using XDocument in LINQ to edit (insert) and save xml document. XDocument doc = XDocument.Load("c:\\sample.xml", LoadOptions.PreserveWhitespace); doc.Save("c:\\sample.xml",SaveOptions.DisableFormatting) sample.xml before doc.Save :
Rocky
  • 405
  • 7
  • 17
9
votes
4 answers

XmlDocument.WriteTo truncates resultant file

Trying to serialize an XmlDocument to file. The XmlDocument is rather large; however, in the debugger I can see that the InnerXml property has all of the XML blob in it -- it's not truncated there. Here's the code that writes my XmlDocument object…
Brad Heller
  • 1,551
  • 5
  • 18
  • 29
9
votes
5 answers

C#: XmlTextWriter.WriteElementString fails on empty strings?

I'm using XmlTextWriter and its WriteElementString method, for example: XmlTextWriter writer = new XmlTextWriter("filename.xml", null); writer.WriteStartElement("User"); writer.WriteElementString("Username",…
Roee Adler
  • 33,434
  • 32
  • 105
  • 133
6
votes
3 answers

How to Prevent the conversion of & to & using XmlTextWriter?

The '&' in the text gets escaped and gets converted to & when creating the xml file using XmlTextWriter but i dont want the conversion to take place how to prevent it? Is there any other way besides using WriteRaw func of xmltextwriter?
kurozakura
  • 2,339
  • 8
  • 28
  • 41
5
votes
4 answers

How can I generate XML with CR, instead of CRLF in XmlTextWriter

I'm generating XML via XmlTextWriter. The file looks good to my eyes, validates (at wc3), and was accepted by the client. But a client vendor is complaining that the line-endings are CRLF, instead of just CR. Well, I'm on a Win32 machine using C#,…
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
5
votes
1 answer

How to save XmlDocument with multiple indentation settings?

I need to save one XmlDocument to file with proper indentation (Formatting.Indented) but some nodes with their children have to be in one line (Formatting.None). How to achieve that since XmlTextWriter accept setting for a whole document? Edit…
shg
  • 81
  • 1
  • 4
4
votes
2 answers

How to indent after newline in xml element value when using an XmlTextWriter?

I am trying to indent after a newline when using an XmlTextWriter So essentially i want this a but using the code below i get this
Simon
  • 33,714
  • 21
  • 133
  • 202
4
votes
3 answers

Memory stream is empty

I need to generate a huge xml file from different sources (functions). I decide to use XmlTextWriter since it uses less memory than XmlDocument. First, initiate an XmlWriter with underlying MemoryStream MemoryStream ms = new…
Summer
  • 161
  • 1
  • 7
  • 13
4
votes
3 answers

Reusing XmlTextWriter class

Is it possible to reuse the same instance of XmlTextWriter class for generating more xml documents? I mean something like this: XmlTextWriter writer = new…
truthseeker
  • 1,220
  • 4
  • 25
  • 58
1
2 3 4 5 6 7 8