c# Reading XML comment using XDocument

前端 未结 3 1391
太阳男子
太阳男子 2020-12-21 12:53

How to read xml comment when using XDocument?

XDocument doc = XDocument.Load(\"joker.xml\");
 foreach (XElement element in doc.Descendants(\"server\"))
              


        
3条回答
  •  [愿得一人]
    2020-12-21 13:38

    Check node type when reading xml. If it's XComment then you are reading comment. E.g. in your case previous node of server element will be comment:

    foreach(var s in doc.Descendants("server"))
    {
        var comment = s.PreviousNode as XComment;
        if (comment != null)
            Console.WriteLine(comment.Value); // outputs "Dummy servers"
    }
    

提交回复
热议问题