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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:14:44+00:00 2026-05-20T02:14:44+00:00

I have an XML file as follows: I uploaded the XML file : http://dl.dropbox.com/u/10773282/2011/result.xml

  • 0

I have an XML file as follows:
XML file

I uploaded the XML file : http://dl.dropbox.com/u/10773282/2011/result.xml . It’s a machine generated XML, so you might need some XML viewer/editor.

I use this C# code to get the elements in CoverageDSPriv/Module/*.

using System;
using System.Xml;
using System.Xml.Linq;

namespace HIR {
  class Dummy {

    static void Main(String[] argv) {

      XDocument doc = XDocument.Load("result.xml");

      var coveragePriv = doc.Descendants("CoverageDSPriv"); //.First();
      var cons = coveragePriv.Elements("Module");

      foreach (var con in cons)
      {
        var id = con.Value;
        Console.WriteLine(id);
      }
    }
  }
}

Running the code, I get this result.

hello.exe6144008016161810hello.exehello.exehello.exe81061hello.exehello.exe!17main_main40030170170010180180011190190012200200013hello.exe!107testfunctiontestfunction(int)40131505001460600158080216120120017140140018AA

I expect to get

hello.exe
61440
...

However, I get just one line of long string.

  • Q1 : What might be wrong?
  • Q2 : How to get the # of elements in cons? I tried cons.Count, but it doesn’t work.
  • Q3 : If I need to get nested value of <CoverageDSPriv><Module><ModuleNmae> I use this code :

    var coveragePriv = doc.Descendants(“CoverageDSPriv”); //.First();
    var cons = coveragePriv.Elements(“Module”).Elements(“ModuleName”);

I can live with this, but if the elements are deeply nested, I might be wanting to have direct way to get the elements. Are there any other ways to do that?

ADDED

var cons = coveragePriv.Elements("Module").Elements();

solves this issue, but for the NamespaceTable, it again prints out all the elements in one line.

hello.exe
61440
0
8
0
1
6
1
61810hello.exehello.exehello.exe81061hello.exehello.exe!17main_main40030170170010180180011190190012200200013hello.exe!107testfunctiontestfunction(int)40131505001460600158080216120120017140140018

Or, Linq to XML can be a better solution, as this post.

  • 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-20T02:14:44+00:00Added an answer on May 20, 2026 at 2:14 am

    It looks to me like you only have one element named Module — so .Value is simply returning you the InnerText of that entire element. Were you intending this instead?

    coveragePriv.Element("Module").Elements();
    

    This would return all the child elements of the Module element, which seems to be what your’e after.

    Update:

    <NamespaceTable> is a child of <Module> but you appear to want to handle it similarly to <Module> in that you want to write out each child element. Thus, one brute-force approach would be to add another loop for <NamespaceTable>:

    foreach (var con in cons)
    {
        if (con.Name == "NamespaceTable") 
        {
            foreach (var nsElement in con.Elements()) 
            {
                var nsId = nsElement.Value;
                Console.WriteLine(nsId);
            }
        }
        else
        {
            var id = con.Value;
            Console.WriteLine(id);
        }
    }
    

    Alternatively, perhaps you’d rather just denormalize them altogether via .Descendents():

    var cons = coveragePriv.Element("Module").Descendents();
    
    foreach (var con in cons)
    {
        var id = con.Value;
        Console.WriteLine(id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this XML file : http://dl.dropbox.com/u/10773282/2011/perf.xml It has two Class elements as is
I have an xml file as follows: <?xml version=1.0 encoding=utf-8?> <Project xmlns=http://schemas.microsoft.com/developer/msbuild/2003 DefaultTargets=Build ToolsVersion=4.0>
i have a XML file as follows: <?xml version=1.0 encoding=utf-8 ?> <publisher> <name>abc</name> <link>http://</link>
say, i have such xml file: <?xml version=1.0?> <catalog> <title>My book catalog</title> <link>http://example.com/catalog</link> <book
I have an XML file as follows, and I'm trying to read the content
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I have a xml file which I need to open with Microsoft Word 2007.
I have an XML file as follows. When I use getElementsByTagName(LEVEL2_ID) , I do
I have my XML File as follows: <states> <state name =Alaska> <Location Name=loc1> <Address>testadd1</Address>
I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8

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.