I have an XML file as follows:

I downloaded the XML file: http://dl.dropbox.com/u/10773282/2011/result.xml . This is an XML generated machine, so you may need an XML editor / editor.
I use this C # code to get 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");
var cons = coveragePriv.Elements("Module");
foreach (var con in cons)
{
var id = con.Value;
Console.WriteLine(id);
}
}
}
}
By running the code, I get this result.
hello.exe6144008016161810hello.exehello.exehello.exe81061hello.exehello.exe!17main_main40030170170010180180011190190012200200013hello.exe!107testfunctiontestfunction(int)40131505001460600158080216120120017140140018AA
I expect to receive
hello.exe
61440
...
However, I get only one line of a long line.
- Q1: What could be wrong?
- Q2: How to get # elements in the cons? I tried
cons.Count, but it does not work. Q3: If I need to get a nested value <CoverageDSPriv><Module><ModuleNmae>, I use this code:
var coveragePriv = doc. ( "CoverageDSPriv" );//.();
var cons = coveragePriv.Elements( "Module" ). ( "ModuleName" );
, , , , . ?
ADDED
var cons = coveragePriv.Elements("Module").Elements();
, NamespaceTable .
hello.exe
61440
0
8
0
1
6
1
61810hello.exehello.exehello.exe81061hello.exehello.exe!17main_main40030170170010180180011190190012200200013hello.exe!107testfunctiontestfunction(int)40131505001460600158080216120120017140140018
Linq to XML , .