// Set SVG Namespace Url
string SvgNamespace = "https://www.w3.org/2000/svg";
string documentPath = Path.Combine(ConstValue.SvgPDAResourceRootDir, "demo2.svg");
using (var document = new SVGDocument(documentPath))
{
// Get root svg element of the document
var svgElement = document.RootElement;
// Create a circle element and set attributes values
var circleElement = (SVGCircleElement)document.CreateElementNS(SvgNamespace, "circle");
circleElement.Cx.BaseVal.Value = 100F;
circleElement.Cy.BaseVal.Value = 100F;
circleElement.R.BaseVal.Value = 50F;
circleElement.SetAttribute("fill", "Salmon");
// Add the circle element as the first child to svg element
svgElement.InsertBefore(circleElement, svgElement.FirstChild);
// Work with the document here...
// Add a polyline and change stroke attributes for all circle and ellipse elements (see later)
document.Save(Path.Combine(ConstValue.SvgPDAResourceRootDir, "demo2.svg"));
}
上面的代码在执行过程中出现以下错误:
无法将类型为”Aspose.Svg.Dom.Element“的对象强制转换为”Aspose.Svg.SVGCircleElement“类型.