Beispiel #1
0
 private static void ValidateValues(Expression xpath, FailureReaction reaction, List <string> returnValues)
 {
     foreach (string value in returnValues)
     {
         ValidateValue(xpath, reaction, value);
     }
 }
Beispiel #2
0
 private static void ValidateValue(Expression xpath, FailureReaction reaction, string returnValue)
 {
     if (reaction == FailureReaction.GenerateErrorOnNull && returnValue == null ||
         (reaction == FailureReaction.GenerateErrorOnEmpty && (returnValue == null || returnValue.Length == 0)))
     {
         throw new Exception(string.Format("Could not find a value at the XPath({0})", xpath.ToString(true)));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Get a string value from the document
        /// </summary>
        /// <param name="xpath"></param>
        /// <returns></returns>
        public string GetValue(Expression xpath, FailureReaction reaction)
        {
            XmlNode node        = this._document.SelectSingleNode(xpath.ToString(true), this._namespaces);
            string  returnValue = null;

            if (node != null)
            {
                if (xpath.IsAttribute)
                {
                    returnValue = node.Value;
                }
                else
                {
                    returnValue = node.InnerText;
                }
            }
            ValidateValue(xpath, reaction, returnValue);
            return(returnValue);
        }
Beispiel #4
0
        /// <summary>
        /// Get all string values that match the given xpath from the document
        /// </summary>
        /// <param name="xpath"></param>
        /// <returns></returns>
        public string[] GetValues(Expression xpath, FailureReaction reaction)
        {
            XmlNodeList   nodeList     = this._document.SelectNodes(xpath.ToString(true), this._namespaces);
            List <string> returnValues = new List <string>();

            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    if (xpath.IsAttribute)
                    {
                        returnValues.Add(node.Value);
                    }
                    else
                    {
                        returnValues.Add(node.InnerText);
                    }
                }
            }
            ValidateValues(xpath, reaction, returnValues);
            return(returnValues.ToArray());
        }
Beispiel #5
0
 /// <summary>
 /// Get a string value from the document
 /// </summary>
 /// <param name="xpath"></param>
 /// <returns></returns>
 public string GetValue(string xpath, FailureReaction reaction)
 {
     return(this.GetValue(new Expression(xpath), reaction));
 }