question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetXML does not output added child elements

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
H1Gdevcommented, Sep 24, 2021

@hakakou

After upgrading to version 3.3.0 from 3.2.3 I was also affected with this problem. Does this mean that after 3.3.0, whenever I add/remove svg elements from Children, the same operations must be duplicated also on Nodes? How about using .Clear and .Insert?

Regarding the operation of Children, I think that the change from 3.2.3 to 3.3.0 has not changed.

Please let me know if you would like a small project demonstrating the problem.

Please create new issue and report problem.

1reaction
mrbean-bremencommented, Sep 24, 2021

@H1Gdev - can you have a look please? I won’t have access to a computer for a week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Get XML only immediate children elements by name
This code would give the following output, showing only direct child elements of the initial root node. NODE num:-1 NODE num:-1.1 NODE num:- ......
Read more >
Using the FOR XML Clause to Return Query Results as XML
As you can see, each column is added as a child element to the <row> element. You do not have to specify the...
Read more >
10 Generating XML Data from the Database
The list of values that follow the XMLAttributes() clause are converted to XML format, and are made as children of the top-level element....
Read more >
xml.etree.ElementTree — The ElementTree XML API
Selects all elements that have a child named tag whose complete text content, including descendants, does not equal the given text . New...
Read more >
XML DOM - Get Node Values
Element nodes do not have a text value. The text value of an element node is stored in a child node. This node...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found