HTML and CSS Reference
In-Depth Information
d. Next you'll examine all of the attribute nodes for the element specified by
the elemNode parameter. Create a for loop to go through the nodes in the
attributes collection for the elemNode parameter. Each time through the loop
increase the value of the nodeCount and attCount variables by 1. Also add the
following text string to the value of the elemText variable
att =' value '
where att is the node name of the attribute node and value is the node value of
the attribute node.
e. After the for loop completes, append the text string > to the value of the
elemText variable.
f. Create a new text node named elemtextnode containing the text of the elemText
variable.
g. Append elemTextNode to spanElem ; append spanElem to liElem ; and finally,
append liElem to nestedList .
7. Create the writetextli() function. The purpose of this function is to create a single
list item for the node tree diagram based on the contents of a text node. The structure
of the list item will be one of the two structures shown in Figure 14-69.
Figure 14-69
list item displaying information about a text node
LI
LI
+--
+--
SPAN
SPAN
class= wsLI
class= textLI
#text
text node value
The function has two parameters: textnode , which represents the text node from the
source document on which the list item is based, and nestedlist , which represents the
nested list that the list item will be appended to. Add the following commands to the
function:
a. Create the lielem variable for a list item element node containing the text
string +-- .
b. Create the spanelem variable for a span element node.
c. Store the node value of the textNode parameter in the variable textstring .
d. Jorge has provided a function named isWhiteSpaceNode() to determine whether
a text node represents white space or not. Call the isWhiteSpaceNode() function
using textstring as the parameter value.
e. If the isWhiteSpaceNode() function returns the value true , then: i) increase the
value of the wsCount variable by 1; ii) set the class name of spanElem to wsli ;
and iii) set the inner HTML of spanElem to the text string #text .
f. If the isWhiteSpaceNode() function returns the value false , then: i) set the class
name of spanElem to textli ; and ii) set the inner HTML of spanElem to the value
of the nodevalue property for the textNode parameter.
g. Append the spanElem node to the liElem node, and then append the liElem node
to the nestedList parameter.
8. Create the maketree() function. The purpose of this function is to recursively gener-
ate all of the nested lists contained in the node tree diagram. The function has two
Search WWH ::




Custom Search