Microsoft Docs

Docs Home Search

DefaultXmlNameTable Class

Namespace: System.Xml

Assembly: System.Xml.dll

Summary

Represents the default implementation of the XmlNameTable class. The default name table uses a hash table to store atomized string objects and provides fast retrieval of these strings.

Syntax

public sealed class DefaultXmlNameTable : XmlNameTable
{
    public DefaultXmlNameTable();
    public override string Add(string str);
    public override string Get(string str);
    public override string Get(char[] key, int startIndex, int length);
}

Remarks

The DefaultXmlNameTable class is optimized for read‑heavy scenarios where many duplicate strings are processed. String atomization reduces memory usage and improves comparison performance because identical strings share the same reference.

Example

using System;
using System.Xml;

class Program
{
    static void Main()
    {
        XmlNameTable nameTable = new DefaultXmlNameTable();

        string s1 = nameTable.Add("example");
        string s2 = nameTable.Get("example");

        Console.WriteLine(Object.ReferenceEquals(s1, s2)); // True
    }
}

Properties

MemberDescription
Add(string str)Atomizes and adds a string to the table.
Get(string str)Retrieves an atomized string if it exists.
Get(char[] key, int startIndex, int length)Retrieves an atomized string from a character array slice.

See Also