Table of Contents

XmlQualifiedEntity Class

Definition

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

Name Description
XmlQualifiedEntity(string)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(string, string)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(string, string, string)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(XmlAnyElementAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(XmlAttributeAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(XmlElementAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

XmlQualifiedEntity(XmlRootAttribute)

Initializes a new instance of the XmlQualifiedEntity class.

Properties

Name Description
HasXmlAnyElementDecoration

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

HasXmlAttributeDecoration

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

HasXmlElementDecoration

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

HasXmlRootDecoration

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

LocalName

Gets the local name of the entity.

Namespace

Gets the namespace URI to associate with the entity.

Prefix

Gets the namespace prefix of the entity.