How can I create an object to represent all elements of an HTML form?

Disclaimer: This is a personal project that I do for fun. I am not going to use existing libraries, as it will bring joy from learning more about wheels .

Speaking, I'm working on a web spider, and I came up with the question of how to present HTML form elements with a single object.

What I want to do is to have an "HTML Document" object that contains an array of all form elements as one of its properties. The problem is that I cannot understand the way tags are presented <input />, as well as tags <select />, as select tags can have multiple child tags <option />.

Is there a good way to present tags <input />that basically store only name / value pairs and tags <select />that have an array of name / value pairs in the same class?

The best idea I've come up with so far is consideration tag <option />tag <select />as an individual form fields, just as I'd imagined <input type="radio" />or <input type="checkbox" />.

So I would have this:

class FormField {
    public string Name { get; set; }
    public string Value { get; set; }
    public string Type { get; set; }
}

And then the collection class for iteration:

  • The collection class will be an "array of arrays". The external array will have one internal array for each name in the HTML document.
  • Its indexer can get fields by name. This index will return an array of objects FormField.
  • When enumerating the fields of the entire document form, each iteration will have an array of objects FormField, since it will be an array of arrays.

, ?

+3
2

dom , http-post?

, ( ). , , ? http-? ?

NameValueCollection, ?

+2

parent-child, body. - . div, p, form .. Children. , select, select htmlObjects

class htmlObject {
    public string Name { get; set; }
    public string Value { get; set; }
    public string Type { get; set; }
    public List<htmlObject> Children { get; }
}

, , "" .

, htmlObject IhtmlObject, . specialize , .

+1

Source: https://habr.com/ru/post/1734681/


All Articles