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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:42:16+00:00 2026-05-17T16:42:16+00:00

i am stuck with this small problem in my code. I am trying to

  • 0

i am stuck with this small problem in my code.

I am trying to make small console application which will write into xml document.
I have used xmldocument and xmlnode concept.

ERROR i am getting is;

*An object reference is required for the non-static field, method, or property ‘Write_xml.Program.give_node(System.Xml.XmlDocument)’ C:\Documents and Settings\Administrator\Desktop\Write_xml\Write_xml\Program.cs*

code is okay except 1 error. I am not able to resolve it ,i want somebody to check it and correct it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace Write_xml
{
    class Program
    {


        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDocument lets = new XmlDocument();
            string path = @"D:\XMLFile.xml";

            doc.Load(path);


            XmlNode Rootnode = doc.SelectSingleNode("Number");

            XmlNode TakenOde = give_node(doc);
            Rootnode.AppendChild(TakenOde);
            doc.Save(path);


        }


        public XmlNode give_node(XmlDocument lets)
        {
              // On this xmldoc we will perform XMLNODE operations
              // for creat new nods and append child nodes
              //XmlNode RootNode = xmldoc.CreateElement("Root");

              XmlNode PersonsNode = lets.CreateElement("Person");


              XmlNode NameNode = lets.CreateElement("Name");
              PersonsNode.AppendChild(NameNode);
              NameNode.InnerText = "1st";


              XmlNode AgeNode = lets.CreateElement("Age");
              PersonsNode.AppendChild(AgeNode);
              AgeNode.InnerText = "2nd";


              XmlNode CityNode = lets.CreateElement("City");
              PersonsNode.AppendChild(CityNode);
              CityNode.InnerText = "3rd";

              return PersonsNode;

          }

    }

}

please let me what small mistake i am doing.

  • 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-17T16:42:16+00:00Added an answer on May 17, 2026 at 4:42 pm

    You’re trying to call an instance method, but without specifying an instance.

    The simplest fix for this is to make the give_node method static.

    I haven’t looked at the rest of the code to see whether it’s okay or not, although give_node should be called GiveNode to follow .NET naming conventions.

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

Sidebar

Related Questions

I am stuck on this problem which I am studying for an exam tomorrow.
I am stuck with a small problem here.. What i am trying to do
I'm writing a small application which exposes a simple REST-ish HTTP API. I'm stuck
I'm trying to run this code: let coins = [50, 25, 10, 5, 2,1]
I'm kinda stuck with this one so I hoped someone could help me. I
I'm a bit stuck on this. Basically I want to do something like the
This is probably easy but I am getting stuck: when I build a solution
I am currently stuck in the design of this solution. The data layer design
I am stuck! this seems really daft but I can not see where I
I know this would be easy with position:fixed, but unfortanately I'm stuck with supporting

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.