Exemple #1
0
        private static Stack <string> traverseXML(XmlNode node, Stack <string> path, string xmlStopToken)
        {
            if (node.Name == xmlStopToken)
            {
                return(path);
            }

            if (node.FirstChild != null)
            {
                path.Push(node.Name);
                var stackFound = MetaData.traverseXML(node.FirstChild, path, xmlStopToken);
                if (stackFound != null)
                {
                    return(stackFound);
                }
                path.Pop();
            }

            if (node.NextSibling != null)
            {
                var stackFound2 = MetaData.traverseXML(node.NextSibling, path, xmlStopToken);
                if (stackFound2 != null)
                {
                    return(stackFound2);
                }
            }

            return(null);
        }
Exemple #2
0
        public static Stack <string> XMLPathToFirstToken(string xml, string xmlStopToken)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            Stack <string> path = MetaData.traverseXML(doc.FirstChild, new Stack <string>(), xmlStopToken);

            return(path);
        }