XmlReader.Prefix Propriété

Définition

En cas de substitution dans une classe dérivée, obtient le préfixe d’espace de noms associé au nœud actuel.

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

Valeur de propriété

Préfixe d’espace de noms associé au nœud actuel.

Exceptions

Une XmlReader méthode a été appelée avant la fin d’une opération asynchrone précédente. Dans ce cas, InvalidOperationException est levée avec le message « Une opération asynchrone est déjà en cours ».

Exemples

L’exemple suivant affiche le nom local de chaque nœud et, s’il existe, l’URI du préfixe et de l’espace de noms.

XmlReader reader = XmlReader.Create("book2.xml");

// Parse the file.  If they exist, display the prefix and
// namespace URI of each node.
while (reader.Read()) {
  if (reader.IsStartElement()) {
    if (reader.Prefix==String.Empty)
                {
                    Console.WriteLine("<{0}>", reader.LocalName);
                }
                else {
      Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
      Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
    }
  }
}
reader.Close();
Dim reader As XmlReader = XmlReader.Create("book2.xml")

' Parse the file.  If they exist, display the prefix and
' namespace URI of each node.
While reader.Read()
  If reader.IsStartElement() Then
    If reader.Prefix = String.Empty Then
      Console.WriteLine("<{0}>", reader.LocalName)
    Else
      Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
      Console.WriteLine(" The namespace URI is " + reader.NamespaceURI)
    End If
  End If
End While
reader.Close()

L’exemple utilise le fichier, book2.xml, comme entrée.

<book xmlns:bk='urn:samples'>
  <title>Pride And Prejudice</title>
  <bk:genre>novel</bk:genre>
</book>

S’applique à