예제 #1
0
        /// <summary>
        /// get XPath for R, A, and BaseType, relative to the root (Component) node.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static string GetPathFromNode(XmlNode node)
        {
            XmlNode p = node.ParentNode;

            if (p == null)
            {
                return("");
            }
            if (node.Name == XmlSerialization.RAIS_PRJ)
            {
                return("");
            }
            if (node.Name != XmlSerialization.RAIS_R && node.Name != XmlSerialization.RAIS_A &&
                node.Name != XmlSerialization.RAIS_I && node.Name != XmlSerialization.RAIS_S &&
                node.Name != XmlSerialization.RAIS_B && node.Name != XmlSerialization.STARTERCLASS)
            {
                throw new MathException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "GetPathFromNode is called for an invalid node {0}", node.Name));
            }
            //
            System.Text.StringBuilder path = new StringBuilder(node.Name);
            if (node.Name != XmlSerialization.RAIS_B && node.Name != XmlSerialization.RAIS_I &&
                node.Name != XmlSerialization.RAIS_S && node.Name != XmlSerialization.STARTERCLASS)
            {
                path.Append("[@");
                path.Append(XmlSerialization.XMLATT_ID);
                path.Append("='");
                path.Append(XmlSerialization.GetNodeID(node).ToString());
                path.Append("']");
            }
            string s = GetPathFromNode(p);

            if (s.Length > 0)
            {
                path.Insert(0, "/");
                path.Insert(0, s);
            }
            return(path.ToString());
        }