Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Reading XML comment using XDocument

Tags:

c#

xml

How to read xml comment when using XDocument?

XDocument doc = XDocument.Load("joker.xml");
 foreach (XElement element in doc.Descendants("server"))
            {
//I use this to read server tag...
}



<?xml version="1.0" encoding="ISO-8859-1"?>
<ho>
    <!-- For X use only -->
    <servers>
        <server NAME="xx" ></server>

    <!-- Dummy servers  -->
        <server NAME="xx" ></server>
        <server NAME="xx" ></server>
    </servers>
</ho>
like image 361
John Ryann Avatar asked Apr 30 '26 10:04

John Ryann


1 Answers

The Node object is the primary data type for the entire DOM.

A node can be an element node, an attribute node, a text node, or any other of the node types explained in the "Node types" chapter.

An XML element is everything from (including) the element's start tag to (including) the element's end tag.

     XDocument xdoc = XDocument.Load("");
       foreach (var node in xdoc.Descendants("servers").Nodes())
        {

            if (node is XComment)
            {
                //THEN  READ YOUR COMMENT 

            }

        }
like image 101
BRAHIM Kamel Avatar answered May 03 '26 00:05

BRAHIM Kamel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!