I would appreciate any advice here. Based on what I have found on the web, I have tried the following to try get what I need working.
I am using Actionscript 2.0 XPath to try and access a <div> value in an xhtml file, but I have this simple piece of Actionscript that I cannot get working:
=====================
stop();
import mx.xpath.XPathAPI;
var rssfeed_xml:XML = new XML();
rssfeed_xml.ignoreWhite = true;
rssfeed_xml.onLoad = function(success:Boolean) {
trace("onload...");
if (success) {
trace("success...");
var elementId:String = "title1";
var elementPath:String = "//div[@id'" + elementId + "']";
found_elements = XPathAPI.selectNodeList(rssfeed_xml.firstChild, elementPath);
if (found_elements.length == 1) {
trace(found_elements[0]);
}
} else {
trace("error loading XML");
}
};
rssfeed_xml.load("test.xhtml");
=====================
My test.xhtml is simple, as such:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Landing</title>
</head>
<div id="mainArea">
<div id="content">
<div id="calloutContent">
<div id="title">Search Our QA Database</div>
<div id="callout1">text1</div>
<div id="callout2">text2</div>
<div id="callout3">text3</div>
</div>
<div id="heroContent">
<div id="title1">text4</div>
<div id="title2">text5</div>
</div>
</div>
</div>
</body>
</html>
In my Actionscript, I am just trying to get the value of <div id="title1">, which is “text4”.
The Actionscript code looks right, but I am not getting anything coming through on the line trace(found_elements[0]);.
Any ideas?
Your problem is coming from the path you have created. This is your current path (with the variable inlined):
There are a couple of things wrong here:
<body>tag//at the start does nothing. To wildcard a node you need to use the*symbol. This will then give you the first node depth. The get to the depth you require you will need to repeat this three more times.=after the attribute name.This path works to target your chosen div:
That path returns the complete node however, so to just extract the text you then request the
firstChild.nodeValue:The obvious problem here is that you have to know pretty much where your target node appears within the document.