C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,378 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hey
This is the xml I have:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Comments Are Just Here-->
<TheOnlyNode>
<ID>15</ID>
...
</TheOnlyNode>
There's only one single comment in the root, after loading this xml with XDocument, how to read that sole comment?
Thanks
Imports System.Xml
Module Module1
Sub Main()
Const xmlString As String =
"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>" &
"<!--Comments Are Just Here-->" &
"<TheOnlyNode>" &
" <ID>15</ID>" &
"</TheOnlyNode>"
Dim xmlDoc = New XmlDocument()
xmlDoc.LoadXml(xmlString)
' only one
Dim oneNode As XmlNode = xmlDoc.SelectSingleNode("//comment()")
If oneNode IsNot Nothing Then
Console.WriteLine(oneNode.Value)
End If
' multiple comments
For Each node As XmlNode In xmlDoc.SelectNodes("//comment()")
Console.WriteLine(node.Value)
Next
Console.ReadKey()
End Sub
End Module