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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:31:26+00:00 2026-06-14T20:31:26+00:00

Im new in C# and XML data ussage. I’ve got the following xml data.

  • 0

Im new in C# and XML data ussage.

I’ve got the following xml data.
This XML file does not appear to have any style information associated with it. The document tree is shown below.

<response>
  <auctions>
   <auction>
    <id>90436</id>
    <user>blabla</user>
    <title>title name</title>
    <value>10000.00</value>
    <period>36</period>
    <www/>
   </auction>
   <auction>
    <id>90436</id>
    <user>blabla</user>
    <title>title name</title>
    <value>10000.00</value>
    <period>36</period>
    <www/>
   </auction>
  </auctions>
 </response>

I use that C# code. (it’s class used by Form1)

    public IXmlNamespaceResolver ns { get; set; }    

public string[] user,id,title,value,period;
    public void XmlRead(string url)
    {
                // Create a new XmlDocument  
                XPathDocument doc = new XPathDocument(url);
                // Create navigator  
                XPathNavigator navigator = doc.CreateNavigator();
                // Get forecast with XPath  
                XPathNodeIterator nodes = navigator.Select("/response/auctions", ns);

                int i = 0;
                foreach (XPathNavigator oCurrentPerson in nodes)
                {   
                    userName[i] = oCurrentPerson.SelectSingleNode("user").Value;
                    userId[i] = int.Parse(oCurrentPerson.SelectSingleNode("id").Value);
                    title[i] = oCurrentPerson.SelectSingleNode("title").Value;
                    value[i] = oCurrentPerson.SelectSingleNode("value").Value;
                    period[i] = oCurrentPerson.SelectSingleNode("period").Value;
                    i++; }
    }

Im getting an error:
Object reference not set to an instance of an object.

userName[i] = oCurrentPerson.SelectSingleNode(“user”).Value;

When I used single string variables like: userName, userId without [] everything worked correctly.

Thanks in advance

  • 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-14T20:31:27+00:00Added an answer on June 14, 2026 at 8:31 pm

    .Net is a strongly-typed world, so use it’s benefits. Create Auction class to hold data from your xml:

    class Auction
    {
        public int Id { get; set; }
        public string User { get; set; }
        public string Title { get; set; }
        public decimal Value { get; set; }
        public int Period { get; set; }
        public string Url { get; set; }
    }
    

    And parse your xml with Linq to Xml:

    XDocument xdoc = XDocument.Load(path_to_xml_file);
    IEnumerable<Auction> auctions =
        from a in xdoc.Descendants("auction")
        select new Auction()
        {
            Id = (int)a.Element("id"),
            User = (string)a.Element("user"),
            Title = (string)a.Element("title"),
            Value = (decimal)a.Element("value"),
            Period = (int)a.Element("period"),
            Url = (string)a.Element("www")
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: ... request data = new request(); data.username = formNick; xml
I'm new to android xml data storage. I have one details.xml file for saving
I'm running the following code: new FileSystemXmlApplicationContext(/data/farm/Server/confData/1000004/contex.xml) and it throws java.io.FileNotFoundException: class path resource
I'm trying to use an xml file for spritesheet data; I have a frame
Using the following code, I push data from an xml file into a classic
I have a WordPress xml data file encoding with utf-8. But the WordPress impoter
I have a long xml data file with 500+ items in it, it comes
Does reading XML data like in the following code create the DOM tree in
I am using a new service to pull xml data from a server. The
XML Data: <configs> <config> <name>XP</name> <browser>IE</browser> <browser>FF</browser> <browser>Chrome</browser> </config> </configs> I'm new to Ruby,

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.