110,538
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" />
</svg>
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "no"));
XElement root = new XElement("svg");
root.Add(
new XAttribute("width", this.Size.Width)
, new XAttribute("height", this.Size.Height)
, new XAttribute("viewBox", "0 0 " + this.Size.Width.ToString() + " " + this.Size.Height.ToString())
, new XAttribute("xmlns", "http://www.w3.org/2000/svg")
, new XAttribute("preserveAspectRatio", "xMidYMid"));
document.Add(root);
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "no"));
XNamespace ns = "http://www.w3.org/2000/svg";
XElement root = new XElement(ns+"svg");
root.Add(
new XAttribute("width", 1)
, new XAttribute("height", 2)
, new XAttribute("viewBox", "0 0 " + 3)
, new XAttribute("preserveAspectRatio", "xMidYMid"),
new XAttribute("xmlns", "http://www.w3.org/2000/svg"),
new XElement( ns+"Child1", "child content"),
new XElement( ns+"Child2", "child content")
);
//Add element
root.AddFirst(new XElement( ns+"Child0", "child content"));
document.Add(root);
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "no"));
XNamespace ns = "http://www.w3.org/2000/svg";
XElement root = new XElement(ns+"svg");
root.Add(
new XAttribute("width", 1)
, new XAttribute("height", 2)
, new XAttribute("viewBox", "0 0 " + 3)
, new XAttribute("preserveAspectRatio", "xMidYMid"),
new XAttribute("xmlns", "http://www.w3.org/2000/svg"),
new XElement( ns+"Child1", "child content"),
new XElement( ns+"Child2", "child content")
);
//Add element
root.AddFirst(new XElement( ns+"Child0", "child content"));
document.Add(root);
void Main()
{
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "no"));
XNamespace ns = "http://www.w3.org/2000/svg";
XElement root = new XElement(ns+"svg");
root.Add(
new XAttribute("width", 1)
, new XAttribute("height", 2)
, new XAttribute("viewBox", "0 0 " + 3)
, new XAttribute("preserveAspectRatio", "xMidYMid"),
new XAttribute("xmlns", "http://www.w3.org/2000/svg"),
new XElement( ns+"Child1", "child content"),
new XElement( ns+"Child2", "child content")
);
document.Add(root);
document.Save("d:\\test1.xml");
}
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<svg width="1" height="2" viewBox="0 0 3" preserveAspectRatio="xMidYMid" xmlns="http://www.w3.org/2000/svg">
<Child1>child content</Child1>
<Child2>child content</Child2>
</svg>
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
doc.AppendChild(declaration);
System.Xml.XmlElement root = doc.CreateElement("svg", "http://www.w3.org/2000/svg");
System.Xml.XmlElement line = doc.CreateElement("line", "http://www.w3.org/2000/svg");
line.SetAttribute("x1","0");
line.SetAttribute("y1","0");
line.SetAttribute("x2","200");
line.SetAttribute("y2","200");
line.SetAttribute("style","stroke:rgb(255,0,0);stroke-width:2");
doc.AppendChild(root);
root.AppendChild(line);
void Main()
{
XDocument document = new XDocument(new XDeclaration("1.0", "UTF-8", "no"));
XNamespace ns = "http://www.w3.org/2000/svg";
XElement root = new XElement(ns+"svg");
root.Add(
new XAttribute("width", 1)
, new XAttribute("height", 2)
, new XAttribute("viewBox", "0 0 " + 3)
, new XAttribute("preserveAspectRatio", "xMidYMid"));
document.Add(root);
document.Save("d:\\test.xml");
}