Table of Contents

Class SvgContent

Namespace
Egami.Svg
Assembly
Egami.Svg.dll

One item of an SvgElement's content, in file order: an element, text, a comment or a processing instruction.

public abstract class SvgContent
Inheritance
SvgContent
Derived
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");
}

Remarks

An item belongs to at most one parent. Adding one that already has a parent throws; Clone() it or Remove() it first.

Properties

Column

Gets the 1-based column this item started at in the file it was read from, or 0 for an item made in code.

public int Column { get; }

Property Value

int

Document

Gets the document whose tree holds this item, or null when it is not in a document.

public SvgDocument? Document { get; }

Property Value

SvgDocument

Line

Gets the 1-based line this item started on in the file it was read from, or 0 for an item made in code.

public int Line { get; }

Property Value

int

Parent

Gets the element this item belongs to, or null for a root or an unattached item.

public SvgElement? Parent { get; }

Property Value

SvgElement

Methods

Clone()

Makes a deep copy without a parent: an element is copied with its attributes and all its content.

public abstract SvgContent Clone()

Returns

SvgContent

The copy.

Remove()

Removes this item from its parent, if it has one.

public void Remove()