private void Main()
{
if (File.Exists(_svgFile))
{
SetSvgSize(_svgFile, spnWidth.Value, spnHeight.Value);
}
}
private void SetSvgSize(string file,decimal width,decimal height)
{
XmlDocument xml = new XmlDocument();
xml.Load(file);
var node = xml.DocumentElement;
UpdateAttribute(node, "width", width.ToString());
UpdateAttribute(node, "height", height.ToString());
xml.Save(file);
}
private void UpdateAttribute(XmlNode node,string attrName,string value)
{
var atts = node.Attributes;
for (int i = 0; i < atts.Count; i++)
{
if (atts[i].Name.Equals(attrName,StringComparison.CurrentCultureIgnoreCase))
{
atts[i].Value = value;
return;
}
}
XmlAttribute tmp = node.OwnerDocument.CreateAttribute(attrName);
tmp.Value = value;
node.Attributes.Append(tmp);
}