|
|
|
|
|
- Declaration
- Properties specific to htmlNode variables
- Creating a text node
- WLanguage functions that use htmlNode variables
htmlNode (Variable type) In french: htmlNoeud
The htmlNode type is used to define all the advanced characteristics of a node of an HTML document. You can define and change the characteristics of this node using different WLanguage properties. Note: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable. MyDocument is htmlDocument  // Retrieves the document from the HTML Display control MyDocument = HTM_Source.DisplayedValue   // Get delivery costs when choosing pickup points depending on the weight // Get the countries // In thead / 2nd TR / 3 first TD sCountry1, sCountry2, sCountry3 is string  // Get array of headers arrHeader is array of htmlNode = MyDocument.FindElementByTag("thead")  // On the first element, take the second child (second TR) // The first child of this TR is the TD of the first country // Inside the TD, there can be other tags (span, p) to manage styles // But the final content is in there, so we can retrieve the InnerHTML from the TD, and // Convert it "directly" to text  sCountry1 = HTMLToText(arrHeader[1].tr[2].td[1]..InnerHTML) // The second child of this TR, is the TD of the second country sCountry2 = HTMLToText(arrHeader[1].tr[2].td[2]..InnerHTML) // The third child of this TR is the TD of the third country sCountry3 = HTMLToText(arrHeader[1].tr[2].td[3]..InnerHTML)  sWeight, sPricingCountry1, sPricingCountry2, sPricingCountry3 are strings  // Modifies the table column titles TABLE_Pricing.COL_Country1.Caption = sCountry1 TABLE_Pricing.COL_Country2.Caption = sCountry2 TABLE_Pricing.COL_Country3.Caption = sCountry3  FOR i = 1 _TO_ 9  // Get the weight and prices per country  sWeight = MyDocument.html.body.div.div.table.tbody.tr[i].td[1]..Text sPricingCountry1 = MyDocument.html.body.div.div.table.tbody.tr[i].td[3]..Text sPricingCountry2 = MyDocument.html.body.div.div.table.tbody.tr[i].td[4]..Text sPricingCountry3 = MyDocument.html.body.div.div.table.tbody.tr[i].td[5]..Text  TABLE_Pricing.AddLine(sWeight, sPricingCountry1, sPricingCountry2, sPricingCountry3)  END
To describe an HTML node, the name of the node can be specified with the TagName property. <Tag name>: Character string Name of the node to create. Properties Properties specific to htmlNode variables The following properties can be used to handle a node of an HTML document: | | | Property name | Type used | Effect |
---|
Attribute | Array of htmlAttribute | Attributes of an htmlNodeElement node. | ChildNode | Array of htmlNode variables | Child node of an htmlNodeElement node. | Count | Integer | Number of elements with the same name. This property is read-only. | Exist | Boolean | - True if the node exists in the document,
- False otherwise.
This property is read-only. | Index | Integer | Index of the node in its parent. This property is read-only. | InnerHTML | Character string | HTML code of the sub-nodes in the current node. | OuterHTML | Character string | HTML code that includes the current node (including the sub-node). This property is read-only. | Parent | htmlNode variable | Parent node, NULL if the node is the root. This property is read-only. | TagName | Character string | Name of the tag if the node is an htmlNodeElement node, empty string ("") otherwise. | Text | Character string | Contents of the node encoded in the current character set. - If the node is of type htmlNodeText, htmlNodeComment or htmlNodeCDATA, the property returns and modifies the node.
- If the node is of type htmlNodeElement, the property returns the concatenation of the text of all subnodes.
When a value is assigned to the property, it empties the subnodes and replaces them with a text subnode containing that value. | Type | Integer constant | Type of node: - htmlComment node: Comment node.
- htmlCDATA node: CDATA node (XHTML compatibility).
- htmlElementNode: Element node, an HTML tag.
- htmlTextNode: Text node.
|
Remarks The following operators are available for a node of type htmlNodeElement: - Operator ".": The operator "." allows to access sub-elements by their tag name..
- Operator ":": The ":" operator is used to access attributes by name..
- Operator [ <indice> ]: This operator is used to access sibling sub-elements of the same name by their index..
- Operator [ <nom> ]: This operator is used to access sub-elements by their tag name..
htmlNodeElement nodes can contain subnodes. Looping through subnodes - "FOR EACH x OF NodeVariable" is used to loop through all the subnodes.
- "FOR EACH x OF NodeVariable IN-DEPTH" is used to recursively loop through all the subnodes.
This syntax is not available.
Creating a text node A text node can be declared using one of the following syntaxes: - Implicit declaration:
o is htmlNode o.Text = "A" - Explicit declaration:
o is htmlNode o.Type = htmlNodeText o.Text = "A"
WLanguage functions that use htmlNode variables - standard syntax:
| | HTMLFindElementByClass | Searches for elements whose "class" attribute matches a specific value in an HTML document (or in an HTML node). | HTMLFindElementByID | Searches for the element whose "ID" attribute matches a specific value in an HTML document (or in an HTML node). | HTMLFindElementByName | Searches for elements whose "name" attribute matches a specific value in an HTML document (or in an HTML node). | HTMLFindElementByTag | Searches for elements that correspond to a tag in an HTML document (or an HTML node). | HTMLInsertAfter | Adds a node after the specified node in an HTML document. | HTMLInsertBefore | Adds a node before the specified node in an HTML document. | HTMLInsertFirstChild | Adds a child at the start of the children of the current node in an HTML document. | HTMLInsertLastChild | Adds a child after the child of the current node in an HTML document. | HTMLModifyAttribute | Adds or changes an attribute of the current node of the HTML document. | HTMLRemove | Removes the specified node and its descendants in an HTML document. | HTMLRemoveAttribute | Removes a given attribute | HTMLRemoveChild | Removes a given node in the current node of an HTML document. | HTMLUnwrapAllChildren | Deletes the specified node in an HTML document without deleting its children, which take its place. | HTMLWrap | Wraps the specified node in a given node of an HTML document. | HTMLWrapAllChildren | Wraps all children of the given node in a new node in an HTML document. |
- prefix syntax:
Related Examples:
|
Unit examples (WINDEV): HTML types (HTMLDocument, HTMLNode, HTMLAttribute)
[ + ] This example shows how to use the HTMLXxx WLanguage types (HTMLDocument, HTMLNode, HTMLAttribute)
|
|
Training (WINDEV): WD HTML Export
[ + ] This example explains how to export data in HTML format with the WLanguage functions. The following topics are presented in this example: 1/ the functions for managing the external files for generating the HTML file 2/ the operations performed on the HTML tags 3/ the generation of an HTML report The generation of an HTML page is performed from the data found in a memory table. By programming The principle consists in generating a text file with a "HTM" extension. The WLanguage function named "fWrite" will be used. This example easily writes the text strings by respecting the syntax of the HTML language. Automatically The principle consists in creating a report on table based on the memory table that was previously filled. The printout is requested with an HTML output.
|
|
Sample components (WINDEV): WD HTML Page Import
[ + ] This example explains how HTML pages can be imported with the WLanguage functions. The following topics are presented in this example: 1/ how to import an object found on a Web site 2/ how to analyze an HTML file Summary of the example supplied with WINDEV: This example is used to save locally an HTML page found on a Web site. This page is analyzed in order to import all its dependencies (images, applets, and so on). This example is not a Web grabber. It can only be used to download the pages one by one. The principle used in this example can also be used to retrieve informations from pages whose format is recognized (example: daily retrieval of share values)
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|