C # creating XML output file without <? Xml version = "1.0" encoding = "utf-8"?>
I'm new to C # development, so maybe this is a very simple question.
I am trying to get output that starts with this:
<ns0:NamespaceEnvelope xmlns:ns0="http://url.to.NamespaceEnvelope/v1.0"> But I get this:
<?xml version="1.0" encoding="utf-8"?> <ns0> This is my source:
XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = "\r\n"; settings.NewLineHandling = NewLineHandling.Replace; using (XmlWriter writer = XmlWriter.Create("employees.xml", settings)) { writer.WriteStartDocument(); writer.WriteStartElement("ns0"); writer.WriteStartElement("Firstsection"); How can I get rid of:
<?xml version="1.0" encoding="utf-8"?> And how can I change:
writer.WriteStartElement("ns0"); To be able to output it as:
<ns0:NamespaceEnvelope xmlns:ns0="http://url.to.NamespaceEnvelope/v1.0"> Like this:
writer.WriteStartElement("ns0:NamespaceEnvelope xmlns:ns0="http://url.to.NamespaceEnvelope/v1.0""); requests ")", probably due to the "environment of the http part.
Any help is appreciated.
+7
Giancarlo
source share2 answers
XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; +14
Konstantin
source share private string RemoveXmlDefinition(string xml) { XDocument xdoc = XDocument.Parse(xml); xdoc.Declaration = null; return xdoc.ToString(); } +7
Only a Curious Mind
source share