Table of Contents

Class XmlQualifiedEntity

Namespace
Cuemon.Xml.Serialization
Assembly
Cuemon.Xml.dll

A class designed to help assure qualified names in XML serializations.

public sealed class XmlQualifiedEntity
Inheritance
XmlQualifiedEntity

Examples

XmlQualifiedEntity represents an XML element or attribute name with optional namespace and prefix, and can be created from XML serialization attributes. This example creates entities from a local name only ("Order"), with a namespace ("http://example.com/orders"), and with a prefix/namespace combination ("o", "Order", "http://example.com/orders"). It then creates entities from XmlRootAttribute("PurchaseOrder"), XmlElementAttribute("LineItem"), and XmlAttributeAttribute("Quantity"), and demonstrates using XmlQualifiedEntity with XmlSerializerOptions to set a custom root name. Console output displays each entity's LocalName, Namespace, Prefix, and decoration flags.

using System;
using System.Xml.Serialization;
using Cuemon.Xml.Serialization;

namespace MyApp.Xml
{
    public class XmlQualifiedEntityExample
    {
        public void Demonstrate()
        {
            // Create an entity from local name only
            var entity1 = new XmlQualifiedEntity("Order");
            Console.WriteLine($"LocalName: {entity1.LocalName}"); // Order
            Console.WriteLine($"Namespace: {entity1.Namespace}"); // (null)
            Console.WriteLine($"Prefix: {entity1.Prefix}"); // (null)

            // Create an entity with local name and namespace
            var entity2 = new XmlQualifiedEntity("Order", "http://example.com/orders");
            Console.WriteLine($"LocalName: {entity2.LocalName}, Namespace: {entity2.Namespace}");

            // Create an entity with prefix, local name, and namespace
            var entity3 = new XmlQualifiedEntity("o", "Order", "http://example.com/orders");
            Console.WriteLine($"Prefix: {entity3.Prefix}, LocalName: {entity3.LocalName}, Namespace: {entity3.Namespace}");

            // Create from XmlRootAttribute
            var rootAttr = new XmlRootAttribute("PurchaseOrder");
            var fromRoot = new XmlQualifiedEntity(rootAttr);
            Console.WriteLine($"From XmlRoot: {fromRoot.LocalName} (Namespace: {fromRoot.Namespace})");
            Console.WriteLine($"HasXmlRootDecoration: {fromRoot.HasXmlRootDecoration}"); // True

            // Create from XmlElementAttribute
            var elemAttr = new XmlElementAttribute("LineItem");
            var fromElement = new XmlQualifiedEntity(elemAttr);
            Console.WriteLine($"From XmlElement: {fromElement.LocalName}");
            Console.WriteLine($"HasXmlElementDecoration: {fromElement.HasXmlElementDecoration}"); // True

            // Create from XmlAttributeAttribute
            var attr = new XmlAttributeAttribute("Quantity");
            var fromAttribute = new XmlQualifiedEntity(attr);
            Console.WriteLine($"From XmlAttribute: {fromAttribute.LocalName}");
            Console.WriteLine($"HasXmlAttributeDecoration: {fromAttribute.HasXmlAttributeDecoration}"); // True

            // Use with XmlSerializerOptions to set a custom root name
            var options = new XmlSerializerOptions
            {
                RootName = new XmlQualifiedEntity("CustomRoot", "http://example.com/schema")
            };
            Console.WriteLine($"Options root name: {options.RootName.LocalName}");

}}
}

Constructors

XmlQualifiedEntity(string)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(string localName)

Parameters

localName string

The local name of the entity.

XmlQualifiedEntity(string, string)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(string localName, string ns)

Parameters

localName string

The local name of the entity.

ns string

The namespace URI to associate with the entity.

XmlQualifiedEntity(string, string, string)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(string prefix, string localName, string ns)

Parameters

prefix string

The namespace prefix of the entity.

localName string

The local name of the entity.

ns string

The namespace URI to associate with the entity.

XmlQualifiedEntity(XmlAnyElementAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(XmlAnyElementAttribute attribute)

Parameters

attribute XmlAnyElementAttribute

The XML related attribute to extract qualified name information about.

XmlQualifiedEntity(XmlAttributeAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(XmlAttributeAttribute attribute)

Parameters

attribute XmlAttributeAttribute

The XML related attribute to extract qualified name information about.

XmlQualifiedEntity(XmlElementAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(XmlElementAttribute attribute)

Parameters

attribute XmlElementAttribute

The XML related attribute to extract qualified name information about.

XmlQualifiedEntity(XmlRootAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

public XmlQualifiedEntity(XmlRootAttribute attribute)

Parameters

attribute XmlRootAttribute

The XML related attribute to extract qualified name information about.

Properties

HasXmlAnyElementDecoration

Gets a value indicating whether this instance was constructed with an XmlAnyAttributeAttribute decoration.

public bool HasXmlAnyElementDecoration { get; }

Property Value

bool

true if this instance was constructed with an XmlAnyAttributeAttribute decoration; otherwise, false.

HasXmlAttributeDecoration

Gets a value indicating whether this instance was constructed with an XmlAttributeAttribute decoration.

public bool HasXmlAttributeDecoration { get; }

Property Value

bool

true if this instance was constructed with an XmlAttributeAttribute decoration; otherwise, false.

HasXmlElementDecoration

Gets a value indicating whether this instance was constructed with an XmlElementAttribute decoration.

public bool HasXmlElementDecoration { get; }

Property Value

bool

true if this instance was constructed with an XmlElementAttribute decoration; otherwise, false.

HasXmlRootDecoration

Gets a value indicating whether this instance was constructed with an XmlRootAttribute decoration.

public bool HasXmlRootDecoration { get; }

Property Value

bool

true if this instance was constructed with an XmlRootAttribute decoration; otherwise, false.

LocalName

Gets the local name of the entity.

public string LocalName { get; }

Property Value

string

The local name of the entity.

Namespace

Gets the namespace URI to associate with the entity.

public string Namespace { get; }

Property Value

string

The namespace URI to associate with the entity.

Prefix

Gets the namespace prefix of the entity.

public string Prefix { get; }

Property Value

string

The namespace prefix of the entity.