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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:38:31+00:00 2026-05-20T08:38:31+00:00

I have an application that is on .net 2.0 and I am having some

  • 0

I have an application that is on .net 2.0 and I am having some difficult with it as I am more use to linq.

The xml file look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<updates>
    <files>
        <file url="files/filename.ext" checksum="06B9EEA618EEFF53D0E9B97C33C4D3DE3492E086" folder="bin" system="0" size="40448" />
        <file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" />
        <file url="files/filename.ext" checksum="CA8078D1FDCBD589D3769D293014154B8854D6A9" folder="" system="0" size="216" />
    </files>
</updates>

The file is downloaded and readed on the fly:

XmlDocument readXML = new XmlDocument();
readXML.LoadXml(xmlData);

Initially i was thinking it would go with something like this:

XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("//files");

foreach (XmlNode node in nodes)
{
 ... im reading it ...
}

But before reading them I need to know how many they are to use on my progress bar and I am also clueless on how to grab the attribute of the file element in this case.

  • How could I count how many “file”
    ELEMENTS I have (count them before entering the foreach ofc) and read their
    attributes ?

I need the count because it will be used to update the progress bar.

Overall it is not reading my xml very well.

  • 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-20T08:38:32+00:00Added an answer on May 20, 2026 at 8:38 am

    before reading them I need to know how many they are to use on my progress bar

    Use the XmlNodeList.Count property. Code example below.

    Overall it is not reading my xml very well

    Here’s some tips on reading Xml with the older Xml library.

    First, XPath is your friend. It lets you query elements pretty quickly, in a way that is (very) vaguely similar to Linq. In this case, you should change your XPath to get the list of child “file” elements, rather than the parent “files” element.

    XmlNodeList nodes = root.SelectNodes("//files");
    

    Becomes

    XmlNodeList files = root.SelectNodes("//file");
    

    The //ElementName searches recursively for all elements with that name. XPath is pretty cool, and you should read up on a bit. Here are some links:

    • http://msdn.microsoft.com/en-us/library/hcebdtae.aspx
    • http://msdn.microsoft.com/en-us/library/d271ytdx.aspx

    Once you have those elements, you can use the XmlElement.Attributes property, coupled with the XmlAttribute.Value property (file.Attributes["url"].Value).

    Or you can use the GetAttribute method.

    Click this link to the documentation on XmlElement for more info. Remember to switch the .Net Framework version to 2.0 on that page.

    XmlElement root = doc.DocumentElement;
    XmlNodeList files = root.SelectNodes("//file"); // file element, not files element
    
    int numberOfFiles = files.Count;
    // Todo: Update progress bar here
    
    foreach (XmlElement file in files) // These are elements, so this cast is safe-ish
    {
        string url = file.GetAttribute("url");
        string folder = file.GetAttribute("folder");
    
        // If not an integer, will throw.  Could use int.TryParse instead
        int system = int.Parse(file.GetAttribute("system"));
        int size = int.Parse(file.GetAttribute("size"));
    
        // convert this to a byte array later
        string checksum = file.GetAttribute("checksum");
    }
    

    For how to convert your checksum into a byte array, see this question:

    How can I convert a hex string to a byte array?

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

Sidebar

Related Questions

I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I have an existing asp.net web application that I'm updating to include some MVC
I have an application that requires .Net. I have found out how to check
I have a .NET application that is meant to be run on a local
I have a .NET application that processes around 300,000 records in a batch import,
I have a Windows application that uses a .NET PropertyGrid control. Is it possible
I have a client-server application that uses .net remoting. The clients are in a
We have a Win32 application that hosts the .NET runtime and opens up .NET
I have an application that is causing a lot of headaches. It's a .NET
I have a ASP.NET application that we've written our own logging module for. My

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.