I want write code in c# which i need to get like this .
<Email version="2.00" xmlns="http://www.portalfiscal.inf.br/nfe"> </Email>
I have tried this but not exact.
XmlTextWriter writer = new XmlTextWriter("D:\\nefe.xml", System.Text.Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("Email");
writer.WriteString("version=2.00 xmlns=Http://www.portalfiscal.inf.br/nfe");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
and output this code is giving like this
<Email>version=2.00 xmlns=Http://www.portalfiscal.inf.br/nfe</Email>
Well yes – you’re calling
WriteString, which writes text content. Your sample XML contains attributes, so you should be usingWriteAttributeString:Do you have to use
XmlWriterthough? Personally I’d recommend using LINQ to XML if you possibly can. It’s not as suitable for writing enormous documents whichXmlWritercan handle easily, but it’s much cleaner when you’re just trying to create a simple document of moderate size:If you do insist on using
XmlWriter, you should use ausingstatement to make sure the output is always closed even if an exception is thrown.