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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:21:23+00:00 2026-05-29T07:21:23+00:00

I have one XML file and I have created on function for retrieving value

  • 0

I have one XML file and I have created on function for retrieving value from XML nodes. Now the problem is if my node have no inner node, still flow goes inside the recursive sentence !

Have a look in my function

/*
XmlDocument x = new XmlDocument(); x.Load(filename);
*/
   public string getValue(string nodename)
    {

        if (File.Exists(filename))
        {


            foreach (XmlNode xx in x.SelectNodes("//"+nodename))
            {
                if (xx.HasChildNodes)
                    getValue(nodename + "//"+xx.ChildNodes[0].Name);
                else
                    return xx.InnerText;
            }   

        }
        return null;
    }

My xmlfile is

<oodle_response stat="ok">
    <current>
        <region>
            <id>barrie</id>
            <name>Barrie</name>
        </region>
        <start>1</start>
        <num>10</num>
    </current>
</oodle_response>

and I am calling my function through

protected void btnLets_Click(object sender, EventArgs e)
{
   string filename = Server.MapPath("~/xmls/newXmlFile.xml";
   oodleXmlParser ox = new oodleXmlParser(filename);
   Response.Write(ox.getValue("oodle_response"));
}
  • 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-29T07:21:24+00:00Added an answer on May 29, 2026 at 7:21 am

    Now the problem is if my node have no inner node, still flow goes inside the recursive sentence !

    It’s not quite right, e.g. in

    <start>1</start>
    

    ‘1’ will be a XmlNode of type XmlNodeType.Text, so you need to check node type of child node instead(or maybe with) xx.HasChildNodes.
    I think your method should look like this

    public static string getValue(string nodename)
        {
    
            if (File.Exists(filename))
            {
    
                int i = 0;
                foreach (XmlNode xx in x.SelectNodes("//" + nodename))
                {                   
                    if (xx.HasChildNodes && xx.ChildNodes[i].NodeType == XmlNodeType.Element)
                        return getValue(nodename + "//" + xx.ChildNodes[i].Name);//i'm sure it should return value
                    else
                        return xx.InnerText;
                    i++;
                }
    
            }
            return null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
I have an XML file which has many section like the one below: <Operations>
i have an xml file sitemap.xml as shown below ..i need to add one
I have an XML file that I'm trying to parse with Linq-to-XML. One of
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I am new to MVC and facing one issue. I have a xml file
I have a .xslt that translates xml from one form to another (I'm not
I have a dynamically created xml file that contains a record with five descriptor
So basically what I have been doing is convert one xml file to a
The Problem I have an issue when I deserialize my xml, one of the

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.