Skip to content

GetXML does not output added child elements #817

Open
@JohnGoldsmith

Description

@JohnGoldsmith

Hi,

I'm having trouble getting back the correct XML after adding sub elements to an SvgDocument

Given the following svg in a file "Min.svg":

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xml:space="preserve">
  <g transform="translate(5, 5)">
    <rect width="25" height="50" />
  </g>
</svg>

and the following code:

void Main()
{
	var path = @"C:\Users\USERNAME\Desktop\Min.svg";
	var svgDoc = SvgDocument.Open(path);
	var grp = svgDoc.Children.OfType<SvgGroup>().FirstOrDefault();
	if (grp != null)
	{
		for (int i = 1; i < 3; i++)
		{
			grp.Children.Add(new SvgCircle
			{
				CenterX = 10 * i,
				CenterY = 10 * i,
				Radius = 50
			});
		}
	}
	svgDoc.GetXML().Dump();
}

This (LINQPad) sample outputs the following text (without the SvgCircle elements being displayed):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg d1p1:space="preserve" ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1" xmlns:d1p1="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2000/svg">
  <g transform="translate(5, 5)">
    <rect width="100" height="50" />
  </g>
</svg>

My main question is where are the added elements?

Other questions are why does the d1p1 alias get added and, also is it correct that the xmlns:ev="http://www.w3.org/2001/xml-events" gets picked up as a custom attribute (SvgDocument.CustomAttributes)?

Many thanks for any insight

John

NuGet version 3.2.3
.Net Framework 4.8
Windows 10 Pro 20H2 (build 19042)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions