public static string Union(string svgdata1,params string[] svgdata) { if (svgdata.Length==0)return svgdata1; SvgDocument doc1 =new SvgDocument(); doc1.PreserveWhitespace =true; doc1.LoadXml(svgdata1); string head=doc1.DocumentElement.CloneNode(false).OuterXml; StringBuilder sb = new StringBuilder(); StringBuilder sbHead = new StringBuilder(); StringBuilder sbDefs = new StringBuilder(); sbHead.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sbHead.Append("\n"); sbHead.Append(head.Replace("</svg>","")); sbHead.Append("\n"); IList idList = new ArrayList(); IList graphList =new ArrayList(); foreach(XmlNode node in doc1.DocumentElement.ChildNodes) { if (node is Defs) { sbDefs.Append(node.OuterXml.Replace("</defs>","")); sbDefs.Append("\n"); foreach(XmlNode node2 in node.ChildNodes) { if (node2 is XmlElement) { idList.Add( (node2 as XmlElement).GetAttribute("id")); } } } if (node is IGraph) { graphList.Add((node as XmlElement).GetAttribute("id")); sb.Append(node.OuterXml); sb.Append("\n"); } } for(int i=0;i<svgdata.Length;i++) { SvgDocument doc2 =new SvgDocument(); doc2.PreserveWhitespace=true; doc2.LoadXml(svgdata[0]); foreach(XmlNode node in doc2.DocumentElement.ChildNodes) { if (node is Defs) { foreach(XmlNode node2 in node.ChildNodes) { if (node2 is XmlElement ) { XmlElement element = node2 as XmlElement; Layer layer=element as Layer; if(layer!=null && layer.GraphList.Count==0 ) { continue; } string id =element.GetAttribute("id"); if (idList.IndexOf(id)>=0)continue; idList.Add(id); sbDefs.Append(element.OuterXml); sbDefs.Append("\n"); } if (node2 is Layer) { string id = ((Layer)node2).ID; if (idList.IndexOf(id) >= 0) continue; idList.Add(id); sbDefs.Append(node2.OuterXml); sbDefs.Append("\n"); } } } if (node is IGraph) { string id = (node as XmlElement).GetAttribute("id"); if (id !=string.Empty && id!=null && graphList.IndexOf(id)>=0)continue; graphList.Add(id); sb.Append(node.OuterXml); sb.Append("\n"); } } doc2.Dispose(); } doc1.Dispose(); sbDefs.Append("</defs>"); sbDefs.Append("\n"); sb.Insert(0,sbDefs.ToString()); sb.Insert(0,sbHead.ToString()); sb.Append("</svg>"); return sb.ToString(); }