Last active
May 5, 2017 05:29
-
-
Save bityob/1ea3e5760fa08d672d5a6e4b3fc05951 to your computer and use it in GitHub Desktop.
Using XmlWriter to write xml without declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<users><user><user_id>1234</user_id><first_name>first</first_name><last_name>last</last_name></user></users> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<users> | |
<user> | |
<user_id>1234</user_id> | |
<first_name>first</first_name> | |
<last_name>last</last_name> | |
</user> | |
</users> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mkbh87 Thanks, you are fast...