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 509905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:03:33+00:00 2026-05-13T07:03:33+00:00

I am writing an XML file in C# using XmlWriter. I am able to

  • 0

I am writing an XML file in C# using XmlWriter. I am able to write Elements using WriteStartElement() method and I can add attributes to this element using WriteAttributeString() method. But if I want to add attribute using dot notation then how to do that?

<Element Attribute1="Value">
    <Element.Attribute2>       //How can i add attribute in this Notation.
          //Add Value of Attribute2
    </Element.Attribute2>
</Element>

I know that I can call WriteStartElement("Element.Attribute") but I m looking for a cleaner approach. Is there any other way to do this?

Edit1:

I have an object(say obj) that is hierarchical(in the form of Tree), each node of this tree is having some properties which can further contain nodes. and I am saving this object in Xml. For that I am using XmlWriter. At runtime I iterate through the obj and read the type of node using GetType().Name and pass it to write an XmlNode and using GetType().GetProperties() I get all properties of that node, then I use a foreach to go through the PropertyInfo array one by one and write the Name of PropertyInfo as attribute but in case when I am having a property that is assigned a node, I need to write the above Dot Notation for that. I am looking for a method where I will just pass my PropertyInfo and the object and it will write for me in desired format.

Thanks for any help!

Edit2:

For a particular node I have properties like Height and Width, like Children which is a Collection and resides implicitly in the hierarchy of Xml, and like Resources which will also be having some properties and each will be represented by nodes under the parent.
But while saving will be written like:

<Parent.Resources>
    <Resource1 ...../>
    <Resource2 ...../>
</Parent.Resources>
  • 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-05-13T07:03:33+00:00Added an answer on May 13, 2026 at 7:03 am

    What would be cleaner than WriteStartElement("Element.Attribute")? It describes exactly what you’re doing – creating a new element, with that name.

    If you definitely want to use XmlWriter, I’d stick with that approach. As Henrik says, however, LINQ to XML is generally a simpler way of creating XML in the first place:

    XElement element = new XElement("Element",
        new XAttribute("Attribute1", "Value"),
        // This could contain nested elements instead of just a text node
        new XElement("Element.Attribute2", "Second value")
    );
    

    EDIT: Now you’ve updated the question, I still don’t see why you want to use this “dot notation”. Isn’t it implicit in the hierarchy of the XML?

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

Sidebar

Related Questions

I need to write model data ( CharField s only) to an XML file
I am writing an XML file in rails(running on RHEL) and will then need
I have a table with 100 K records. I am writing an XML file
I am writing the necessary business logic in C# methods by using class library
Is there a way to define jpa entity classes outside of persistence.xml (i.e. in
I am writing a proxy service for caching the queries that my mobile app
For a very large site such as a Social Network (say Facebook), which method
I am new to webservices in general. I am trying to write a Java
I have a function that gets a string passed to it. When testing the
What I did is creating a local folder named images and retrieving the images

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.