Ejemplo n.º 1
0
        private XMLPair ReadXMLPair(string keyValuePair)
        {
            string[] s    = keyValuePair.Split('=');
            XMLPair  pair = new XMLPair();

            pair.PropertyName = s[0];
            s[1]       = s[1].TrimStart('"');
            s[1]       = s[1].TrimEnd('"');
            pair.Value = s[1];
            //Debug.WriteLine(pair.PropertyName + "=" + pair.Value);
            return(pair);
        }
Ejemplo n.º 2
0
        public void StartMethod()
        {
            List <XMLNode> nodes = navPage.metaTab.Nodes;

            List <string> metaToRemove = new List <string> {
                "?xml", "!DOCTYPE", "metadata", "title", "desc"
            };

            foreach (string metaName in metaToRemove)
            {
                if (nodes.Any(x => x.Name == metaName))
                {
                    XMLNode nodeToRemove = nodes.Find(x => x.Name == metaName);
                    if (nodeToRemove.Children.Count == 0)
                    {
                        if (nodeToRemove.Parent == null)
                        {
                            nodes.Remove(nodeToRemove);
                        }
                        else
                        {
                            XMLNode parent = nodeToRemove.Parent;
                            parent.Children.Remove(nodeToRemove);
                            nodes.Remove(nodeToRemove);
                        }
                    }
                    else
                    {
                        RemoveChildren(ref nodes, nodeToRemove.Children);
                        if (nodeToRemove.Parent == null)
                        {
                            nodes.Remove(nodeToRemove);
                        }
                        else
                        {
                            XMLNode parent = nodeToRemove.Parent;
                            parent.Children.Remove(nodeToRemove);
                            nodes.Remove(nodeToRemove);
                        }
                    }
                }
            }
            XMLNode defsNode = nodes.Find(x => x.Name == "defs");
            XMLNode svgNode  = nodes.Find(x => x.Name == "svg");

            if (defsNode != null)
            {
                if (defsNode.Children.Count == 0)
                {
                    svgNode.Children.Remove(defsNode);
                    nodes.Remove(defsNode);
                }
            }

            XMLNode sodipodi = nodes.Find(x => x.Name == "sodipodi:namedview");

            if (sodipodi != null)
            {
                svgNode.Children.Remove(sodipodi);
                nodes.Remove(sodipodi);
            }
            List <XMLPair> attr  = svgNode.Attributes.ToList();
            XMLPair        xmlns = attr.Find(x => x.PropertyName == "xmlns");

            attr.Remove(xmlns);
            foreach (XMLPair pair in svgNode.Attributes)
            {
                if (!pair.PropertyName.StartsWith("xmlns:"))
                {
                    attr.Remove(pair);
                }
            }
            svgNode.Attributes = attr;

            bool[] toStay = new bool[svgNode.Attributes.Count];
            for (int i = 0; i < svgNode.Attributes.Count; i++)
            {
                toStay[i] = false;
            }

            string toTrim = "xmlns:";

            for (int counter = 0; counter < svgNode.Attributes.Count; counter++)
            {
                XMLPair pair = svgNode.Attributes[counter];
                foreach (XMLNode node in nodes)
                {
                    if (node.Name != "svg")
                    {
                        if (node.Attributes.Count != 0)
                        {
                            foreach (XMLPair pairs in node.Attributes)
                            {
                                string name = pair.PropertyName.Replace(toTrim, "");
                                if (pairs.PropertyName.StartsWith(name))
                                {
                                    toStay[counter] = true;
                                }
                            }
                        }
                    }
                }
            }
            int n = svgNode.Attributes.Count;

            for (int j = n - 1; j >= 0; j--)
            {
                if (toStay[j] == false)
                {
                    svgNode.Attributes.RemoveAt(j);
                }
            }
            svgNode.Attributes.Add(xmlns);
            RemoveNotNeededIDs(ref nodes);
            RemoveChildren(ref nodes, nodes.Find(x => x.Name == "svg").Children);
            string path = MakeFileNamePath();

            SaveToFile(nodes, path);
            OpenFile(path);
        }