//    /**
        //     * Prepare to submit this form. A Connection object is created with the request set up from the form values. You
        //     * can then set up other options (like user-agent, timeout, cookies), then execute it.
        //     * @return a connection prepared from the values of this form.
        //     * @throws IllegalArgumentException if the form's absolute action URL cannot be determined. Make sure you pass the
        //     * document's base URI when parsing.
        //     */
        //    public Connection submit() {
        //        String action = hasAttr("action") ? absUrl("action") : baseUri();
        //        Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing.");
        //        Connection.Method method = attr("method").toUpperCase().equals("POST") ?
        //                Connection.Method.POST : Connection.Method.GET;
        //
        //        return Jsoup.connect(action)
        //                .data(formData())
        //                .method(method);
        //    }
        /// <summary>Get the data that this form submits.</summary>
        /// <remarks>
        /// Get the data that this form submits. The returned list is a copy of the data, and changes to the contents of the
        /// list will not be reflected in the DOM.
        /// </remarks>
        /// <returns>a list of key vals</returns>
        public virtual IList <KeyVal> FormData()
        {
            List <KeyVal> data = new List <KeyVal>();

            // iterate the form control elements and accumulate their values
            foreach (iText.StyledXmlParser.Jsoup.Nodes.Element el in elements)
            {
                if (!el.Tag().IsFormSubmittable())
                {
                    continue;
                }
                // contents are form listable, superset of submitable
                if (el.HasAttr("disabled"))
                {
                    continue;
                }
                // skip disabled form inputs
                String name = el.Attr("name");
                if (name.Length == 0)
                {
                    continue;
                }
                String type = el.Attr("type");
                if ("select".Equals(el.TagName()))
                {
                    iText.StyledXmlParser.Jsoup.Select.Elements options = el.Select("option[selected]");
                    bool set = false;
                    foreach (iText.StyledXmlParser.Jsoup.Nodes.Element option in options)
                    {
                        data.Add(KeyVal.Create(name, option.Val()));
                        set = true;
                    }
                    if (!set)
                    {
                        iText.StyledXmlParser.Jsoup.Nodes.Element option = el.Select("option").First();
                        if (option != null)
                        {
                            data.Add(KeyVal.Create(name, option.Val()));
                        }
                    }
                }
                else
                {
                    if ("checkbox".EqualsIgnoreCase(type) || "radio".EqualsIgnoreCase(type))
                    {
                        // only add checkbox or radio if they have the checked attribute
                        if (el.HasAttr("checked"))
                        {
                            String val = el.Val().Length > 0 ? el.Val() : "on";
                            data.Add(KeyVal.Create(name, val));
                        }
                    }
                    else
                    {
                        data.Add(KeyVal.Create(name, el.Val()));
                    }
                }
            }
            return(data);
        }
Beispiel #2
0
 /// <summary>Creates a deep copy of these elements.</summary>
 /// <returns>a deep copy</returns>
 public Object Clone()
 {
     iText.StyledXmlParser.Jsoup.Select.Elements clone = new iText.StyledXmlParser.Jsoup.Select.Elements(Count);
     foreach (Element e in this)
     {
         clone.Add((Element)e.Clone());
     }
     return(clone);
 }
Beispiel #3
0
 /// <summary>Test if any of the matched elements match the supplied query.</summary>
 /// <param name="query">A selector</param>
 /// <returns>true if at least one element in the list matches the query.</returns>
 public virtual bool Is(String query)
 {
     iText.StyledXmlParser.Jsoup.Select.Elements children = Select(query);
     return(!children.IsEmpty());
 }
Beispiel #4
0
 /// <summary>
 /// Remove elements from this list that match the
 /// <see cref="Selector"/>
 /// query.
 /// <p>
 /// E.g. HTML:
 /// <c>&lt;div class=logo&gt;One&lt;/div&gt; &lt;div&gt;Two&lt;/div&gt;</c>
 /// <br />
 /// <code>Elements divs = doc.select("div").not(".logo");</code><br />
 /// Result:
 /// <c>divs: [&lt;div&gt;Two&lt;/div&gt;]</c>
 /// <p>
 /// </summary>
 /// <param name="query">the selector query whose results should be removed from these elements</param>
 /// <returns>a new elements list that contains only the filtered results</returns>
 public virtual iText.StyledXmlParser.Jsoup.Select.Elements Not(String query)
 {
     iText.StyledXmlParser.Jsoup.Select.Elements @out = Selector.Select(query, this);
     return(Selector.FilterOut(this, @out));
 }