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

  • SEARCH
  • Home
  • 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 4123322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:35:48+00:00 2026-05-20T23:35:48+00:00

Hey all i have code to write to an xml doc from asp string

  • 0

Hey all i have code to write to an xml doc from asp

        string filePath = Server.MapPath("../XML/MyXmlDoc.xml");
        XmlDocument xmlDoc = new XmlDocument();

        try
        {
            xmlDoc.Load(filePath);
        }
        catch (System.IO.FileNotFoundException)
        {
            //if file is not found, create a new xml file
            XmlTextWriter xmlWriter = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
            xmlWriter.Formatting = Formatting.Indented;
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            string startElement = "markings";
            xmlWriter.WriteStartElement(startElement);
            xmlWriter.Close();
            xmlDoc.Load(filePath);
        }
        XmlNode root = xmlDoc.DocumentElement;
        XmlElement mainNode = xmlDoc.CreateElement("mark");
        XmlElement childNode1 = xmlDoc.CreateElement("studentFirstName");
        XmlElement childNode2 = xmlDoc.CreateElement("studentLastName");
        XmlElement childNode3 = xmlDoc.CreateElement("className");
        XmlElement childNode4 = xmlDoc.CreateElement("marks");

        XmlText childTextNode1 = xmlDoc.CreateTextNode("");
        XmlText childTextNode2 = xmlDoc.CreateTextNode("");
        XmlText childTextNode3 = xmlDoc.CreateTextNode("");
        XmlText childTextNode4 = xmlDoc.CreateTextNode("");

        root.AppendChild(mainNode);

        //this portion can be added to a foreach loop if you need to add multiple records

        childTextNode1.Value = "John";
        childTextNode2.Value = "Doe";
        childTextNode3.Value = "Biology";
        childTextNode4.Value = "99%";

        mainNode.AppendChild(childNode1);
        childNode1.AppendChild(childTextNode1);
        mainNode.AppendChild(childNode2);
        childNode2.AppendChild(childTextNode2);
        mainNode.AppendChild(childNode3);
        childNode3.AppendChild(childTextNode3);
        mainNode.AppendChild(childNode4);
        childNode4.AppendChild(childTextNode4);

        //end of loop section

        xmlDoc.Save(filePath);

which works fine but i want to store the xml in the following structure

graph

   set name="John Doe" value="99";

/graph

instead of

name John Doe /name
value 99 /value

is there a way to store the xml like this? thanks all

  • 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-20T23:35:49+00:00Added an answer on May 20, 2026 at 11:35 pm

    You can add an attribute to your XmlElement by using the following syntax (C#) :

    XmlAttribute value = xmlDoc.CreateAttribute("value");
    childNode1.attributes.appendChild(value);    
    

    Hope this helps !

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

Sidebar

Related Questions

Hey all, this is the code i have to check for a day thats
Hey all. Here is the scenario. I have the below code, and I'm needing
Let's say I have the string Hey . I would like to determine all
Hey all, i have converted some C# PayPal API Code over to VB.net. I
Hey all i am new to XML parsing on VB.net. This is the code
Hey all i am trying to get the value from this code: <DIV id=lcm_simlive_countdown>00
Hey all i have an XML file that i am trying to loop though.
Hey all! This bit of code always returns 0, even though errcheck will have
hey all, I have made a socket server in C# for a flash game
Hey all. I have a question on how to implement the following with Django.

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.