Table of Contents

Class SvgAttribute

Namespace
Egami.Svg
Assembly
Egami.Svg.dll

An attribute of an SvgElement: its name, namespace, the prefix it was written with, and its value.

[SuppressMessage("Naming", "CA1711", Justification = "An XML attribute, as XAttribute; not a .NET attribute.")]
public sealed class SvgAttribute
Inheritance
SvgAttribute
Inherited Members

Examples

SvgDocument document = SvgDocument.Parse(Icon);

// Elements, attributes and text are an editable tree, like XDocument's.
SvgElement body = document.FindById("body")!;
body.Attributes["fill"] = "#c33";
body.Attributes.Set("href", "#other", SvgNamespaces.XLink, "xlink");

SvgElement dot = new("circle");
dot.Attributes["cx"] = "12";
dot.Attributes["cy"] = "12";
dot.Attributes["r"] = "3";
document.Root.Children.Add(dot);
document.Root.Children.Add(new SvgComment(" added in code "));

foreach (SvgElement element in document.Root.Elements())
{
    Console.WriteLine($"{element.Name}: {element.Attributes.Count} attributes");
}

Constructors

SvgAttribute(string, string, string?, string?)

Initializes a new instance of the SvgAttribute class.

public SvgAttribute(string name, string value, string? namespaceUri = null, string? prefix = null)

Parameters

name string

The local name, such as fill or href.

value string

The value, with entities expanded.

namespaceUri string

The namespace, such as XLink, or null for none.

prefix string

The prefix a save writes, such as xlink, or null to pick one.

Properties

Name

Gets the local name, such as fill or href.

public string Name { get; }

Property Value

string

Namespace

Gets the namespace, or null for an attribute in no namespace, as most SVG attributes are.

public string? Namespace { get; }

Property Value

string

Prefix

Gets the prefix a save writes, or null.

public string? Prefix { get; }

Property Value

string

Value

Gets the value, with entities expanded.

public string Value { get; }

Property Value

string

Methods

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.