Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml Inheritance: System.ValueType

Syntax

Summary

Represents a namespace-qualified XML name: a local name, a namespace URI, and an optional prefix.

Usage

An XmlName is a qualified XML name: a local name, a namespace URI, and an optional prefix. The library uses it wherever a name has to carry its namespace, for example XmlTypeInfo.RootName, XmlPropertyInfo.Name, and the keys of XmlExtensionData.Attributes. Create a name with the local name alone, or add the namespace URI and the prefix:
Two names are equal when their local names and namespace URIs are equal. The prefix is kept so that a name can be written the way it was read, and it plays no part in equality or in hash codes.

Remarks

Two names are equal when XmlName.LocalName and XmlName.NamespaceUri are equal by ordinal comparison. XmlName.Prefix only affects how the name is written. It is not used for equality or for mapping.

Examples

Compare and print names

ToString returns prefix:local when the name has a prefix, {uri}local when it has a namespace and no prefix, and the local name otherwise.
The code produces the following output:
View the complete sample on GitHub

Considerations

  • XmlName is a readonly struct that holds three string references. Copying it is cheap, and creating one allocates nothing beyond the strings you pass in.
  • The constructor checks only that the local name isn’t null, empty, or white space. It doesn’t check that the parts are valid XML names.
  • A null namespace URI or prefix passed to the constructor becomes an empty string, so NamespaceUri and Prefix are never null in a name you create.
  • Comparison is ordinal. Namespace URIs are compared character by character, as the Namespaces in XML recommendation requires, so urn:Example and urn:example are different namespaces.
  • The output of ToString is for display. The {uri}local form is not XML syntax.
  • default(XmlName) doesn’t go through the constructor, so its LocalName, NamespaceUri, and Prefix are all null. Don’t use it as a name.

Constructors

.ctor

Initializes a new instance of the XmlName struct with the specified local name, namespace URI, and prefix.

Syntax

Parameters

Exceptions

Examples

Remarks

Pass a namespace URI without a prefix when the name is only compared with other names. XmlName.ToString writes the prefix only when it is not empty.

.ctor Inherited

Inherited from System.ValueType

Syntax

.ctor Inherited

Inherited from object

Syntax

Properties

LocalName

Gets the local part of the name.

Syntax

Property Value

Type: string The local name.

NamespaceUri

Gets the namespace URI of the name.

Syntax

Property Value

Type: string The namespace URI, or an empty string if the name is in no namespace.

Prefix

Gets the prefix of the name.

Syntax

Property Value

Type: string The prefix, or an empty string if the name has no prefix.

Methods

Equals

Determines whether this name and a specified XmlName have the same local name and namespace URI.

Syntax

Parameters

Returns

Type: bool true if other has the same local name and namespace URI as this name, by ordinal comparison; otherwise, false.

Equals Override

Determines whether this name and a specified object are equal.

Syntax

Parameters

Returns

Type: bool true if obj is an XmlName with the same local name and namespace URI as this name; otherwise, false.

Equals Override

Inherited from System.ValueType

Syntax

Parameters

Returns

Type: bool

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Override

Returns the hash code for this name, computed from XmlName.LocalName and XmlName.NamespaceUri.

Syntax

Returns

Type: int A 32-bit signed integer hash code.

GetHashCode Override

Inherited from System.ValueType

Syntax

Returns

Type: int

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

ToString Override

Returns a string that represents this name.

Syntax

Returns

Type: string prefix:local if the name has a prefix; otherwise, {uri}local if the name has a namespace URI; otherwise, the local name.

ToString Override

Inherited from System.ValueType

Syntax

Returns

Type: string?

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?
  • CloudNimble.Text.Xml.XmlNamespaces
  • CloudNimble.Text.Xml.Serialization.XmlExtensionData
  • CloudNimble.Text.Xml.Serialization.XmlPropertyInfo
  • CloudNimble.Text.Xml.Serialization.XmlTypeInfo
  • CloudNimble.Text.Xml.Nodes.XmlElementNode