Skip to content

Instantly share code, notes, and snippets.

@bityob
Last active May 5, 2017 05:29
Show Gist options
  • Save bityob/1ea3e5760fa08d672d5a6e4b3fc05951 to your computer and use it in GitHub Desktop.
Save bityob/1ea3e5760fa08d672d5a6e4b3fc05951 to your computer and use it in GitHub Desktop.
Using XmlWriter to write xml without declaration
<users><user><user_id>1234</user_id><first_name>first</first_name><last_name>last</last_name></user></users>
<users>
<user>
<user_id>1234</user_id>
<first_name>first</first_name>
<last_name>last</last_name>
</user>
</users>
using System.Xml;
namespace XmlTools
{
class XmlWithoutDeclaration
{
static void Main(string[] args)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
XmlWriter writer = XmlWriter.Create("users.xml", settings);
writer.WriteStartDocument();
writer.WriteStartElement("users");
writer.WriteStartElement("user");
writer.WriteElementString("user_id", "1234");
writer.WriteElementString("first_name", "first");
writer.WriteElementString("last_name", "last");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
}
}
@bityob
Copy link
Author

bityob commented May 4, 2017

@mkbh87 Thanks, you are fast...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment