public void ContainsOnlyQueriedNodes()
        {
            IXML xml  = new XMLCursor("<t6><z9 a='433'><item>a</item><item>b</item></z9><z9 a='432'><item>c</item></z9></t6>");
            IXML root = xml.Nodes("/t6/z9[@a='433']")[0];

            Assert.Empty(root.Values("/z9[@a='432']"));
        }
 /// <summary>
 /// Texts, extracted from a xml with xpath.
 /// </summary>
 public XMLTexts(IXML xml, string xpath) : base(() =>
                                                new Mapped <string, IText>(
                                                    str => new Atoms.Text.TextOf(str),
                                                    xml.Values(xpath)
                                                    ),
                                                false
                                                )
 {
 }
        public void AppliesXpathToClonedNode()
        {
            IXML xml  = new XMLCursor("<t6><z9 a='433'/></t6>");
            IXML root = xml.Nodes("/t6")[0];

            Assert.Equal(
                "433",
                root.Values("//z9/@a")[0]
                );
        }
 /// <summary>
 /// A string in a document, retrieved by xpath.
 /// </summary>
 internal XMLString(IXML xml, string xpath, Func <string> fallback)
 {
     this.result = new ScalarOf <string>(() =>
     {
         var matches = xml.Values(xpath);
         var result  = string.Empty;
         if (matches.Count < 1)
         {
             result = fallback();
         }
         else if (matches.Count > 1)
         {
             throw new ArgumentException(
                 $"Cannot retrieve single value with XPath '{xpath}' because it resulted in multiple values in document{Environment.NewLine}'{xml.AsNode().ToString()}'."
                 );
         }
         else
         {
             result = matches[0];
         }
         return(result);
     });
 }
Exemple #5
0
 /// <summary>
 /// Strings in a document, retrieved by xpath.
 /// </summary>
 public XMLStrings(string xpath, IXML xml) : base(
         () => xml.Values(xpath),
         false
         )
 {
 }