How can I add standalone="no" in creating an XML file?
-
I am able to create a XML file with:
with the following codes:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.GetEncoding("ISO-8859-1");XmlWriter writer = XmlWriter.Create("C:\\\\XML files\\\\XML\_File.xml", settings);
How can I add standalone="no" after encoding="ISO-8859-1" as
Thanks for any help :doh:
-
I am able to create a XML file with:
with the following codes:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.GetEncoding("ISO-8859-1");XmlWriter writer = XmlWriter.Create("C:\\\\XML files\\\\XML\_File.xml", settings);
How can I add standalone="no" after encoding="ISO-8859-1" as
Thanks for any help :doh:
This page[^] has answer. And also check this method[^]
thatraja
-
This page[^] has answer. And also check this method[^]
thatraja
When I use the link and set:
writer.WriteStartDocument(true)
; then I have
However when I set:
writer.WriteStartDocument(false)
; then I have
*) What I need as mentionned before:
Thanks for help, we are close! :doh:
-
I am able to create a XML file with:
with the following codes:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.GetEncoding("ISO-8859-1");XmlWriter writer = XmlWriter.Create("C:\\\\XML files\\\\XML\_File.xml", settings);
How can I add standalone="no" after encoding="ISO-8859-1" as
Thanks for any help :doh:
I had the same problem. I had to go with XmlDocument: XmlNode docNode = doc.CreateXmlDeclaration("1.0", "iso-8859-1", "no"); I'm guessing you are viewing this in a browser instead of a text file. One thing that you may notice is that the "ISO" becomes capitalized in a browser, but if you look at it with a text editor like Notepad, it looks the way you want it. Also, the browser translates "no" to "false". If you want to see what it looks like exactly, use Notepad. You might also try this: XmlSerializer xmlSer = new XmlSerializer(typeof(T)); using (MemoryStream mem = new MemoryStream()) { using (XmlWriter writer = XmlWriter.Create(mem)) { string doubleQuote = ((char)34).ToString(); string s = "version=" + doubleQuote + "1.0" + doubleQuote + " encoding=" + doubleQuote + "iso-8859-1" + doubleQuote + " standalone=" + doubleQuote + "no" + doubleQuote; writer.WriteProcessingInstruction("xml", s); xmlSer.Serialize(writer, objectToSerialize); } }
-
When I use the link and set:
writer.WriteStartDocument(true)
; then I have
However when I set:
writer.WriteStartDocument(false)
; then I have
*) What I need as mentionned before:
Thanks for help, we are close! :doh:
-
I had the same problem. I had to go with XmlDocument: XmlNode docNode = doc.CreateXmlDeclaration("1.0", "iso-8859-1", "no"); I'm guessing you are viewing this in a browser instead of a text file. One thing that you may notice is that the "ISO" becomes capitalized in a browser, but if you look at it with a text editor like Notepad, it looks the way you want it. Also, the browser translates "no" to "false". If you want to see what it looks like exactly, use Notepad. You might also try this: XmlSerializer xmlSer = new XmlSerializer(typeof(T)); using (MemoryStream mem = new MemoryStream()) { using (XmlWriter writer = XmlWriter.Create(mem)) { string doubleQuote = ((char)34).ToString(); string s = "version=" + doubleQuote + "1.0" + doubleQuote + " encoding=" + doubleQuote + "iso-8859-1" + doubleQuote + " standalone=" + doubleQuote + "no" + doubleQuote; writer.WriteProcessingInstruction("xml", s); xmlSer.Serialize(writer, objectToSerialize); } }
Yes, you are right about seeing it with Notepad which I have: Thanks for clarifying it :)
-
I had the same problem. I had to go with XmlDocument: XmlNode docNode = doc.CreateXmlDeclaration("1.0", "iso-8859-1", "no"); I'm guessing you are viewing this in a browser instead of a text file. One thing that you may notice is that the "ISO" becomes capitalized in a browser, but if you look at it with a text editor like Notepad, it looks the way you want it. Also, the browser translates "no" to "false". If you want to see what it looks like exactly, use Notepad. You might also try this: XmlSerializer xmlSer = new XmlSerializer(typeof(T)); using (MemoryStream mem = new MemoryStream()) { using (XmlWriter writer = XmlWriter.Create(mem)) { string doubleQuote = ((char)34).ToString(); string s = "version=" + doubleQuote + "1.0" + doubleQuote + " encoding=" + doubleQuote + "iso-8859-1" + doubleQuote + " standalone=" + doubleQuote + "no" + doubleQuote; writer.WriteProcessingInstruction("xml", s); xmlSer.Serialize(writer, objectToSerialize); } }
Yes, you are right which writer.WriteStartDocument(false); I do have if seeing it with Notepad. Thanks for clarifying it ;)
-
Thanks for the link, it is OK if I viewing my xml file with Notepad! :-D