次の方法で共有


XmlReader.LocalName Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a derived class, gets the local name of the current node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property LocalName As String
public abstract string LocalName { get; }

Property Value

Type: System.String
The name of the current node with the prefix removed. For example, LocalName is book for the element <bk:book>.
For node types that do not have a name (like Text, Comment, and so on), this property returns String.Empty.

Examples

Dim output As New StringBuilder()

Dim xmlString As String = _
        "<book xmlns:bk='urn:samples'>" & _
            "<title>Pride And Prejudice</title>" & _
            "<bk:genre>novel</bk:genre>" & _
        "</book>"

' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

    ' 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
                output.Append("<" + reader.LocalName + ">")
            Else
                output.Append("<" + reader.Prefix + ":" + reader.LocalName + ">")
                output.AppendLine(" The namespace URI is " + reader.NamespaceURI)
            End If
        End If
    End While
End Using

OutputTextBlock.Text = output.ToString()

StringBuilder output = new StringBuilder();

String xmlString =
    @"<book xmlns:bk='urn:samples'>
    <title>Pride And Prejudice</title>
    <bk:genre>novel</bk:genre>
</book>";

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    // 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)
                output.Append("<" + reader.LocalName + ">");
            else
            {
                output.Append("<" + reader.Prefix + ":" + reader.LocalName + ">");
                output.AppendLine(" The namespace URI is " + reader.NamespaceURI);
            }
        }
    }
}

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.