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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:02:21+00:00 2026-05-26T23:02:21+00:00

I’m trying to parse an NZB file (which is XML) and sum the bytes

  • 0

I’m trying to parse an NZB file (which is XML) and sum the bytes attributes. Sometimes it works perfectly and sometimes it returns zero, and I can’t figure out why. The NZB files have identical structure as far as I can tell.

private Int32 processNZB(string sFilename)
{
    XDocument xFile = XDocument.Load(sFilename);

    Int32 sum = xFile.Descendants("segment").Sum(x => (int)x.Attribute("bytes"));

    sum = (int)(sum / 1024 / 1024); // bytes -> MB
    return sum;
}

Source code and sample files can be found here: http://jonathanslaven.com/.for/.stackoverflow/

Is there an obvious reason this isn’t working? Is there a better way of doing this? Thanks for your help.

  • 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-26T23:02:22+00:00Added an answer on May 26, 2026 at 11:02 pm

    Perhaps the initial value of sum is less than 10242 bytes? As you are performing integer division, the result will be trucated, so anything less than 10242 bytes will return zero.

    For instance, the example NZB file @ wikipedia would give 0 when run through your algorithm.

    EDIT:

    Upon inspection of the “bad” files (actually, it’s the “good” one that isn’t following the spec), the reason it’s not working is that the default namespace of the root element is "http://www.newzbin.com/DTD/2003/nzb" meaning any child nodes will inherit this namespace.

    This means that your query .Descendants("segment") returns no nodes. Attaching the correct namespace fixes the problem.

    The following shows how you might modify your code to read such a file.

    private int ProcessNzb(string sFilename)
    {
        XDocument xDoc = XDocument.Load(sFilename);
        return xDoc
            .Descendants(xDoc.Root.Name.Namespace + "segment")
            .Sum(x => (int) x.Attribute("bytes")) / 1024 / 1024;
    }
    

    As an aside, I’d avoid posting files that suggest involvement in contraband.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
In my XML file chapters tag has more chapter tag.i need to display chapters
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small

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.