Catrobat.IDE.Core.Utilities.Helpers.ReferenceHelper.GetXPath C# (CSharp) Method

GetXPath() static private method

static private GetXPath ( System.Xml.Linq.XElement node ) : string
node System.Xml.Linq.XElement
return string
        static string GetXPath(XElement node)
        {
            StringBuilder builder = new StringBuilder();
            while (node != null)
            {
                switch (node.NodeType)
                {
                    case XmlNodeType.Element:
                        int index = GetElementIndex(node);
                        builder.Insert(0, "/" + node.Name + "[" + index + "]");
                        node = node.Parent;
                        break;
                    case XmlNodeType.Document:
                        return builder.ToString();
                    default:
                        throw new ArgumentException("Only elements and attributes are supported");
                }
            }
            throw new ArgumentException("Node was not in a document");
        }