Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET XMLWriter: How to change what's in the header?
    primarykey
    data
    text
    <p>I have a requirement to make an XML file - and the partner is rather sticky about the header. Apparently, the header must be exactly this: </p> <pre><code>&lt;?xml version="1.0"?&gt; </code></pre> <p>But whenever I create an XML file I get extraneous properties like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt; </code></pre> <p>The hacker in me wants to stop using XMLWriter to make the file so that I have more control over the header; "no problem, I'll just write a loop that makes its own XML tags as a StreamWriter or something, forget this XMLWriter object..." but I must admit that XMLWriter has been rather elegant to use so far; surely there must be something where I can change the XMLWriterSettings object to say "stop putting your custom properties in to the XML header please", right?</p> <p>Here's the relevant VB code:</p> <pre><code> Dim settings As New XmlWriterSettings() settings.Indent = True settings.IndentChars = " " settings.NewLineChars = "\n" Using writer As XmlWriter = XmlWriter.Create(strFileName, settings) writer.WriteStartDocument(True) For Each kvp As KeyValuePair(Of String, String) In dictArguments Dim key As String = kvp.Key Dim value As String = kvp.Value writer.WriteStartElement(key) writer.WriteString(value) writer.WriteEndElement() Next End Using </code></pre> <p>Works perfectly; but I can't find a way to control the header. I can find a way to remove it entirely of course but that's not what we want to do.</p> <p><strong>Edit: thanks for the help; so far once we removed the WriteStartDocument it now no longer displays standalone = yes. I can't get it to stop adding the encoding however. Any ideas?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload