Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:16:21+00:00 2026-06-16T00:16:21+00:00

I want write code in c# which i need to get like this .

  • 0

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> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:16:21+00:00Added an answer on June 16, 2026 at 12:16 am

    Well yes – you’re calling WriteString, which writes text content. Your sample XML contains attributes, so you should be using WriteAttributeString:

    writer.WriteAttributeString("version", "2.00");
    writer.WriteAttributeString("xmlns", "http://www.portalfiscal.inf.br/nfe");
    

    Do you have to use XmlWriter though? Personally I’d recommend using LINQ to XML if you possibly can. It’s not as suitable for writing enormous documents which XmlWriter can handle easily, but it’s much cleaner when you’re just trying to create a simple document of moderate size:

    XNamespace ns = "http://www.portalfiscal.inf.br/nfe";
    var doc = new XDocument(new XElement(ns + "Email",
                                         new XAttribute("xmlns", ns.ToString()),
                                         new XAttribute("version", "2.00")));
    doc.Save("nefe.xml");
    

    If you do insist on using XmlWriter, you should use a using statement to make sure the output is always closed even if an exception is thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write a little code analyzer which parses nested structures and translates into
I want to write a simple task which will update and commit source code
I want to write some plugin to analysis Java source code. Which part of
How do I write code to connect through Windows VPN client? I want this
I have a table in SQL Server which looks like this: ID Code Name
I wrote the code in PHP like this and I need to delete the
I want to take screenshot programatically. So that i write code for it like,
I want to write clean code. So When writing a method I want to
I want to write a code to backup my Sql Server 2008 Database using
I want to write a php code that can search for multiple keywords separated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.