Questions tagged [xmlwriter]

System.Xml.XmlWriter class is part of .NET framework that provides non-cached, forward-only way to generate streams or files that contain XML data.

Documentation:

489 questions
6
votes
1 answer

How to mock System.Xml.XmlWriter.WriteAttributeString() with moq?

When I run the following code in my test, Mock mockXmlWriter = new Mock(); Language language = Language.GetLangauge(langId); language.WriteXml(mockXmlWriter.Object); mockXmlWriter.Verify(writer =>…
mo.
  • 4,165
  • 3
  • 34
  • 45
5
votes
1 answer

XmlWriter.WriteRaw escapes xml when the writer was created via XElement.CreateWriter

I have noticed that XmlWriter.WriteRaw appears to not work properly (it escapes xml characters) when the writer is created using XElement.CreateWriter. The below test case reproduces the problem. Is my usage incorrect? Does anyone know how to…
Stuart Lange
  • 4,049
  • 6
  • 24
  • 30
5
votes
3 answers

C# XML - Multiple Namespace Declaration with XML Writer

I am trying to create an XML document with multiple namespaces using System.Xml.Xmlwriter in C# and am recieving the following error on compile: The prefix '' cannot be redefined from '' to 'http://www.acme.com/BOF' within the same start element…
JMK
  • 27,273
  • 52
  • 163
  • 280
5
votes
1 answer

XmlWriter inserting spaces when xml:space=preserve

Given this code (C#, .NET 3.5 SP1): var doc = new XmlDocument(); doc.LoadXml("" + "" + "content" + "content" + ""); var text = new…
Miral
  • 12,637
  • 4
  • 53
  • 93
5
votes
1 answer

XML WriteAttributeString error

When I write this entry here: with this…
aghaux
  • 729
  • 4
  • 14
  • 38
5
votes
3 answers

Creating an XML Element object from an XML Writer in C#

I'm writing a Windows service in C#. I've got an XmlWriter which is contains the output of an XSLT transformation. I need to get the XML into an XMLElement object to pass to a web service. What is the best way to do this?
macleojw
  • 4,113
  • 10
  • 43
  • 63
5
votes
3 answers

XmlReader behaves different with line breaks

If the data is on a single line the index=int.Parse(logDataReader.ReadElementContentAsString()); and value=double.Parse(logDataReader.ReadElementContentAsString(), cause the cursor to move forward. If I take those calls out I see it loop 6 times…
paparazzo
  • 44,497
  • 23
  • 105
  • 176
5
votes
3 answers

Add start element with prefix without namespace

Is there any way to use WriteStartElement funtion in XmlWriter like this: XmlWriter.WriteStartElement("prefix", "name", null); Error occured: System.ArgumentException: 'Unable to use prefix with empty namespace.' I do not want to set namespace…
Dominik
  • 209
  • 2
  • 13
5
votes
1 answer

C# XmlWriter namespace issues

I'm using XmlWriter and I'm struggling to create the following XML tag.
digital_fate
  • 567
  • 1
  • 5
  • 15
5
votes
4 answers

How to write XML files?

I want to write a not so complicated but large file within my app and be able to send it by mail (using MFMailComposeViewController) Since NSXMLElement and related classes are not ported to iPhone SDK what options do I have for creating XML…
nacho4d
  • 43,720
  • 45
  • 157
  • 240
5
votes
1 answer

PHP XMLReader read , edit Node , write XMLWriter

I have an XML file which is very very large (millions of records). Due to speed and memory constraints I plan to use XMLReader/XMLWriter. I need to read the file, getting one record, change its attribute, and finally save XML again. For testing I…
Rami.Q
  • 2,486
  • 2
  • 19
  • 30
5
votes
1 answer

Can one force XMLWriter to write elements in single quotes?

Here's my code: var ptFirstName = tboxFirstName.Text; writer.WriteAttributeString("first",ptFirstName); note that ptFirstName will end up in double quotes even if I use ptFirstName = ptFirstName.Replace("\"","'"); This does not work either since…
user2058253
  • 191
  • 1
  • 2
  • 4
5
votes
1 answer

How to append to large XML files in C# using memory efficiently

Is there some way I can combine two XmlDocuments without holding the first in memory? I have to cycle through a list of up to a hundred large (~300MB) XML files, appending to each up to 1000 nodes, repeating the whole process several times (as the…
Overlord_Dave
  • 894
  • 10
  • 27
4
votes
2 answers

How to save XML without characters being escaped?

In my C# app, XML data may contain arbitrary element text that's already been pre-processed, so that (among other things) illegal characters have been converted to their escaped (xml character entity encoded) form. Example: this &…
Dave G
  • 115
  • 1
  • 11
4
votes
2 answers

How to set XmlWriter.XmlWriterSettings when created from XPathNavigator.AppendChild()?

I need to set the OmitXmlDeclaration property of the XmlWriterSettings for a XmlWriter to false to not have XML declarations created. The issue is that I have created the XmlWriter from a call of a XPathNavigator.AppendChild() method. Code below: …
Chris Woodruff
  • 1,323
  • 3
  • 14
  • 30