System.Xml.XPath.XPathNavigator.Compile C# (CSharp) Method

Compile() public method

public Compile ( string xpath ) : XPathExpression
xpath string
return XPathExpression
        public virtual XPathExpression Compile(string xpath)
        {
            return XPathExpression.Compile(xpath);
        }

Usage Example

        /// <summary>
        /// Récupère la valeur de l'attribut du noeud recherché dans le fichier de configuration
        /// </summary>
        /// <param name="xPathString">Expression XPath de recherche du noeud</param>
        /// <param name="attribute">Attribut à rechercher</param>
        /// <returns>Une ArrayList contenant la liste des attributs recherchés</returns>
        public ArrayList GetAttributes(string xPathString, string attribute)
        {
            // Initilisation des variables
                    XPathNodeIterator xpathNodeIterator;
                    XPathExpression expr;

                    ArrayList attributes = new ArrayList();

                    // Parcours du fichier XML
                    try
                    {
                           xpathNavigator = xpathDoc.CreateNavigator();
                           expr = xpathNavigator.Compile(xPathString);
                           xpathNodeIterator = xpathNavigator.Select(expr);

                           while (xpathNodeIterator.MoveNext())
                           {
                                  // On récupère l'attribut
                                  attributes.Add(xpathNodeIterator.Current.GetAttribute(attribute, ""));
                           }
                    }
                    catch (Exception e)
                    {
                    }

                    return attributes;
        }
All Usage Examples Of System.Xml.XPath.XPathNavigator::Compile