C
Chris Lacey
Is anyone aware why the following code (intended to write XML into a
memory-based XmlTextWriter, and return the complete document as a string)
produces badly formed XML due to the resultant string always commencing with
a question mark
string xmlRequestString;
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream,
Encoding.UTF8);
xmlTextWriter.WriteStartDocument();
xmlTextWriter.WriteStartElement("element");
xmlTextWriter.WriteStartElement("subelement");
xmlTextWriter.WriteAttributeString("attribute", "attributeValue");
xmlTextWriter.WriteString("string");
xmlTextWriter.WriteEndElement();
xmlTextWriter.WriteEndElement();
xmlTextWriter.WriteEndDocument();
xmlTextWriter.Close();
xmlRequestString = Encoding.UTF8.GetString(memoryStream.ToArray());
Console.WriteLine(xmlRequestString);
This returns the following (note the preceding question mark):
?<?xml version="1.0" encoding="utf-8"?><element><subelement
attribute="attribute
Value">string</subelement></element>
Any ideas or assistance very gratefully received!!
Many thanks,
Chris.
memory-based XmlTextWriter, and return the complete document as a string)
produces badly formed XML due to the resultant string always commencing with
a question mark
string xmlRequestString;
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream,
Encoding.UTF8);
xmlTextWriter.WriteStartDocument();
xmlTextWriter.WriteStartElement("element");
xmlTextWriter.WriteStartElement("subelement");
xmlTextWriter.WriteAttributeString("attribute", "attributeValue");
xmlTextWriter.WriteString("string");
xmlTextWriter.WriteEndElement();
xmlTextWriter.WriteEndElement();
xmlTextWriter.WriteEndDocument();
xmlTextWriter.Close();
xmlRequestString = Encoding.UTF8.GetString(memoryStream.ToArray());
Console.WriteLine(xmlRequestString);
This returns the following (note the preceding question mark):
?<?xml version="1.0" encoding="utf-8"?><element><subelement
attribute="attribute
Value">string</subelement></element>
Any ideas or assistance very gratefully received!!
Many thanks,
Chris.