XmlReader.Name Propriedade

Definição

Quando é substituído em uma classe derivada, obtém o nome qualificado do nó atual.When overridden in a derived class, gets the qualified name of the current node.

public:
 virtual property System::String ^ Name { System::String ^ get(); };
public:
 abstract property System::String ^ Name { System::String ^ get(); };
public virtual string Name { get; }
public abstract string Name { get; }
member this.Name : string
Public Overridable ReadOnly Property Name As String
Public MustOverride ReadOnly Property Name As String

Valor da propriedade

String

O nome qualificado do nó atual.The qualified name of the current node. Por exemplo, Name é bk:book para o elemento < BK: Book > .For example, Name is bk:book for the element <bk:book>.

O nome retornado depende do NodeType do nó.The name returned is dependent on the NodeType of the node. Os seguintes tipos de nó retornam os valores listados.The following node types return the listed values. Todos os outros tipos de nó retornam uma cadeia de caracteres vazia.All other node types return an empty string.

Tipo de nóNode type NomeName
Attribute O nome do atributo.The name of the attribute.
DocumentType O nome do tipo de documento.The document type name.
Element O nome da marcação.The tag name.
EntityReference O nome da entidade referenciada.The name of the entity referenced.
ProcessingInstruction O destino da instrução de processamento.The target of the processing instruction.
XmlDeclaration A cadeia de caracteres literal xml.The literal string xml.

Exceções

Um método XmlReader foi chamado antes do término de uma operação assíncrona anterior.An XmlReader method was called before a previous asynchronous operation finished. Nesse caso, InvalidOperationException será gerado com a mensagem “Uma operação assíncrona já está em andamento”.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

Exemplos

O exemplo a seguir lê um arquivo XML e exibe cada um dos nós.The following example reads an XML file and displays each of the nodes.

XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create("items.xml", settings);

reader.MoveToContent();
  // Parse the file and display each of the nodes.
  while (reader.Read()) {
    switch (reader.NodeType) {
      case XmlNodeType.Element:
          Console.Write("<{0}>", reader.Name);
          break;
      case XmlNodeType.Text:
          Console.Write(reader.Value);
          break;
       case XmlNodeType.CDATA:
           Console.Write("<![CDATA[{0}]]>", reader.Value);
           break;
       case XmlNodeType.ProcessingInstruction:
           Console.Write("<?{0} {1}?>", reader.Name, reader.Value);
           break;
       case XmlNodeType.Comment:
           Console.Write("<!--{0}-->", reader.Value);
           break;
       case XmlNodeType.XmlDeclaration:
           Console.Write("<?xml version='1.0'?>");
           break;
       case XmlNodeType.Document:
           break;
       case XmlNodeType.DocumentType:
           Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
           break;
       case XmlNodeType.EntityReference:
           Console.Write(reader.Name);
           break;
       case XmlNodeType.EndElement:
           Console.Write("</{0}>", reader.Name);
           break;
   }
}
Dim settings As New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
Dim reader As XmlReader = XmlReader.Create("items.xml", settings)
reader.MoveToContent()
' Parse the file and display each of the nodes.
While reader.Read()
  Select Case reader.NodeType
    Case XmlNodeType.Element
      Console.Write("<{0}>", reader.Name)
    Case XmlNodeType.Text
      Console.Write(reader.Value)
    Case XmlNodeType.CDATA
      Console.Write("<![CDATA[{0}]]>", reader.Value)
    Case XmlNodeType.ProcessingInstruction
      Console.Write("<?{0} {1}?>", reader.Name, reader.Value)
    Case XmlNodeType.Comment
      Console.Write("<!--{0}-->", reader.Value)
    Case XmlNodeType.XmlDeclaration
      Console.Write("<?xml version='1.0'?>")
    Case XmlNodeType.Document
    Case XmlNodeType.DocumentType
      Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value)
    Case XmlNodeType.EntityReference
      Console.Write(reader.Name)
    Case XmlNodeType.EndElement
      Console.Write("</{0}>", reader.Name)
  End Select
End While

O exemplo usa o items.xml arquivo.The sample uses the items.xml file.

<?xml version="1.0"?>
<!-- This is a sample XML document -->
<!DOCTYPE Items [<!ENTITY number "123">]>
<Items>
  <Item>Test with an entity: &number;</Item>
  <Item>Test with a child element <more/> stuff</Item>
  <Item>Test with a CDATA section <![CDATA[<456>]]> def</Item>
  <Item>Test with a char entity: &#65;</Item>
  <!-- Fourteen chars in this element.-->
  <Item>1234567890ABCD</Item>
</Items>

Aplica-se a

Confira também