DiaIconFinder.GetPathFromNode C# (CSharp) Method

GetPathFromNode() public static method

public static GetPathFromNode ( string sheet, string objectname, XPathNavigator nav ) : string
sheet string
objectname string
nav XPathNavigator
return string
    public static string GetPathFromNode(string sheet, string objectname,
					XPathNavigator nav)
    {
        XmlNamespaceManager manager = new XmlNamespaceManager (nav.NameTable);
        manager.AddNamespace ("dia",
              "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns");

        XPathExpression iconquery =
          nav.Compile ("/dia:sheet/dia:contents/dia:object[@name='" + objectname +
           "']/dia:icon");
        iconquery.SetContext (manager);
        XPathNodeIterator objectdescriptions = nav.Select (iconquery);
        while (objectdescriptions.MoveNext ())
          {
        return objectdescriptions.Current.Value;
          }

        return GetPathFromObjectName (sheet, objectname);
    }

Usage Example

Example #1
0
    public DiaIconFinder()
    {
        icons        = new DiaIcons();
        objecticons  = new Dictionary <string, string> ();
        objectsheets = new Dictionary <string, string> ();
        System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("sheets");
        foreach (System.IO.FileInfo f in dir.GetFiles("*.sheet"))
        {
            string              sheet    = f.Name.Replace(".sheet", "");
            XPathDocument       document = new XPathDocument(f.FullName);
            XPathNavigator      nav      = document.CreateNavigator();
            XmlNamespaceManager manager  = new XmlNamespaceManager(nav.NameTable);
            manager.AddNamespace("dia",
                                 "http://www.lysator.liu.se/~alla/dia/dia-sheet-ns");

            XPathExpression query =
                nav.Compile("/dia:sheet/dia:contents/dia:object");
            query.SetContext(manager);
            XPathNodeIterator links = nav.Select(query);

            while (links.MoveNext())
            {
                try
                {
                    string objectname = links.Current.GetAttribute("name", "");
                    string iconpath   =
                        DiaIconFinder.GetPathFromNode(sheet, objectname, nav);
                    if ("" != iconpath)
                    {
                        objecticons.Add(objectname, iconpath);
                    }
                    objectsheets.Add(objectname, sheet);
                }
                catch
                {
                }
            }
        }
        System.IO.DirectoryInfo sdir = new System.IO.DirectoryInfo("shapes");
        foreach (System.IO.DirectoryInfo idir in sdir.GetDirectories())
        {
            GetShapesInDir(idir);
            foreach (System.IO.DirectoryInfo jdir in idir.GetDirectories())
            {
                GetShapesInDir(jdir);
            }
        }
    }