I have a requirement to create an XML file - and the partner is pretty sticky in the header. Apparently the title should be just like this:
<?xml version="1.0"?>
But whenever I create an XML file, I get extraneous properties as follows:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
The hacker in me wants to stop using XMLWriter to create the file so that I have more control over the header; "No problem, Iโll just write a loop that creates its own XML tags like StreamWriter or something like that, forget about this XMLWriter ...", but I have to admit that XMLWriter is pretty elegant to use so far; of course, there must be something where I can change the XMLWriterSettings object to say "stop putting your custom properties in the XML header, please," right?
Here is the corresponding VB 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
Works great; but I cannot find a way to manage the header. I can find a way to completely remove it, but thatโs not what we want to do.
Edit: thanks for the help; while we removed WriteStartDocument, now it no longer displays standalone = yes. However, I cannot make it stop adding encoding. Any ideas?
source share