c# - Cannot read XML comments using LINQ to XML -


i cannot retrieve xml node comments. there different way retrieve it? .value did not work either. not find here in stackoverflow. doing:

<?xml version="1.0" encoding="utf-8"?> <components>     <component name="aaa">         <sample>             <!-- blah blah blah -->          </sample>         <data>             <!-- blah blah blah -->                      </data>     </component>      <component name="bbb">         <sample>             <!-- blah blah blah -->          </sample>         <data>             <!-- blah blah blah -->                      </data>          </component>     </components>  public class component {     public string name { get; set; }     public string sample { get; set; }     public string data { get; set; } }      xdocument doc = xdocument.load(xmlfilename);      component components = doc.descendants("component")         .select(x => new component         {             name = (string)x.attribute("name"),             sample = (string)x.element("sample"), //cannot read value             data = (string)x.element("data") //cannot read value         }); 

any ideas?

try this:

var components =     doc         .descendants("component")         .select(x => new component()         {             name = (string)x.attribute("name"),             sample = string.join("", x.element("sample").nodes().oftype<xcomment>()),             data = string.join("", x.element("data").nodes().oftype<xcomment>()),         }); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -