XmlTextReader.HasValue 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指示当前节点是否可以具有 Value 其他 String.Empty节点。
public:
virtual property bool HasValue { bool get(); };
public override bool HasValue { get; }
member this.HasValue : bool
Public Overrides ReadOnly Property HasValue As Boolean
属性值
true 如果读取器当前定位的节点可以有 ; Value否则为 false。
示例
以下示例显示每个可具有值的节点的值。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("book1.xml");
reader.WhitespaceHandling = WhitespaceHandling.None;
//Parse the file and display each node.
while (reader.Read())
{
if (reader.HasValue)
Console.WriteLine("({0}) {1}={2}", reader.NodeType, reader.Name, reader.Value);
else
Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name);
}
}
finally
{
if (reader!=null)
reader.Close();
}
}
} // End class
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
'Load the reader with the XML file.
reader = New XmlTextReader("book1.xml")
reader.WhitespaceHandling = WhitespaceHandling.None
'Parse the file and display each node.
While reader.Read()
If reader.HasValue Then
Console.WriteLine("({0}) {1}={2}", reader.NodeType, reader.Name, reader.Value)
Else
Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name)
End If
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
该示例使用该文件 book1.xml作为输入。
<?xml version='1.0' ?>
<!DOCTYPE book [<!ENTITY h 'hardcover'>]>
<book>
<title>Pride And Prejudice</title>
<misc>&h;</misc>
</book>
注解
注释
建议您使用XmlReader方法创建XmlReader.Create实例,以利用新功能。
下表列出了具有要返回值的节点类型。
| 节点类型 | 价值 |
|---|---|
Attribute |
特性的值。 |
CDATA |
CDATA 部分的内容。 |
Comment |
注释的内容。 |
DocumentType |
内部子集。 |
ProcessingInstruction |
整个内容,不包括目标。 |
SignificantWhitespace |
混合内容模型中标记之间的空白。 |
Text |
文本节点的内容。 |
Whitespace |
标记之间的空白。 |
XmlDeclaration |
声明的内容。 |