Prev | Current Page 401 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Accessing the text content of an element is simple but you cannot forget that the text is a node itself and
must be accessed as such. In the preceding example, to get the inner content of the variable a , you cannot
use the nodeValue variable because this field is not available on nodes of type Element and you
must use the firstChild() function.
trace(a.firstChild().nodeValue);
If you do not know the exact content of an Element node and you want to obtain a string representation
of this content, you can write a simple function that works in a similar way to the innerHTML property
in the HTML Dom (see Chapter 9 for further details).
class XmlUtil
{
public static function innerXML(x : Xml)
{
return if(x == null)
??????;
else if(x.nodeType == Xml.Document || x.nodeType == Xml.Element)
{
var b = new StringBuf();
for(n in x)
b.add(n.toString());
b.toString();
} else
x.toString();
}
}
Creating a document
Creating an XML document presents no difficulties. You only have to ensure that after a node has been
created it is added to some node of your document.


Pages:
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413