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 xmlRequestStrin g;
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream,
Encoding.UTF8);
xmlTextWriter.W riteStartDocume nt();
xmlTextWriter.W riteStartElemen t("element");
xmlTextWriter.W riteStartElemen t("subelement") ;
xmlTextWriter.W riteAttributeSt ring("attribute ", "attributeValue ");
xmlTextWriter.W riteString("str ing");
xmlTextWriter.W riteEndElement( );
xmlTextWriter.W riteEndElement( );
xmlTextWriter.W riteEndDocument ();
xmlTextWriter.C lose();
xmlRequestStrin g = Encoding.UTF8.G etString(memory Stream.ToArray( ));
Console.WriteLi ne(xmlRequestSt ring);
This returns the following (note the preceding question mark):
?<?xml version="1.0" encoding="utf-8"?><element><s ubelement
attribute="attr ibute
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 xmlRequestStrin g;
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlTextWriter = new XmlTextWriter(m emoryStream,
Encoding.UTF8);
xmlTextWriter.W riteStartDocume nt();
xmlTextWriter.W riteStartElemen t("element");
xmlTextWriter.W riteStartElemen t("subelement") ;
xmlTextWriter.W riteAttributeSt ring("attribute ", "attributeValue ");
xmlTextWriter.W riteString("str ing");
xmlTextWriter.W riteEndElement( );
xmlTextWriter.W riteEndElement( );
xmlTextWriter.W riteEndDocument ();
xmlTextWriter.C lose();
xmlRequestStrin g = Encoding.UTF8.G etString(memory Stream.ToArray( ));
Console.WriteLi ne(xmlRequestSt ring);
This returns the following (note the preceding question mark):
?<?xml version="1.0" encoding="utf-8"?><element><s ubelement
attribute="attr ibute
Value">string</subelement></element>
Any ideas or assistance very gratefully received!!
Many thanks,
Chris.
Comment