HTMLElement Reference

HTMLElement is an AppleScript libraryt that represets HTML document structure with programming.

You can built a structre of a HTML document by script object through well arranged object orientied interface. And the object structre can output well fomatted HTML data.

This library is useful when a kind of data is converted into HTML data.

The root object of HTMLElement can be made by the constructor method of make_with. First argument of make_with is name of the tag. Attributes of the tag can be specified in second argument as a list of lists e.g. {{attribute1, value1}, {attribute2, value2}, ...}.

Child objects can be appended by methods of push_element_with, push_comment_with.

The contents of HTML tags can be appended by push.

To obtain text data of HTML, as_html can be used.

use HTMLElement : script "HTMLElement"

tell HTMLElement's make_with("html", {})
tell push_element_with("head", {})
tell push_element_with("title", {})
push("Welcome to HTMLElement")
end tell
end tell
tell push_element_with("body", {})
tell push_element_with("p", {})
push("hello")
end tell
set body_tag to it
end tell
set html_tag to it
end tell

set comment_tag to HTMLElement's comment_with("this is comment", {})
body_tag's push(comment_tag)

log html_tag's as_html()
(*<html>
<head>
<title>Welcome to HTMLElement</title>
</head>
<body>
<p>hello</p>
<!-- this is comment -->
</body>
</html>*)

Constructor Methods

make_with

Make a new HTMLElement instance

comment_with

Make a new HTMLElement instance for a comment tag

Appending Child Element and Contents

push

Append text into the contents of the tag.

push_element_with

Append a new HTMLElement instance as a child node.

push_comment_with

Append a new comment instance as a child node.

Output

as_html

Return HTML text data.

Accessor Methods

element_name

Retun element name.

set_element_name

Set element name.

attribute_value

Return atttibute value of specified name.

set_attribute

Set attibute of the tag.