Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




XPath Query Prob.



hello.
i am using Xpath for as 2.0 i cannot seem to query 2 attributes is this possilbe ?


var query:Object = XPath.selectNodes(structure, "//YEAR[@ID = '2006'] and //YEAR/MONTH/WEEK[@ID = '12']");



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 07-25-2007, 12:01 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

XPath Query String Question
maybe this isnt' the best place for the question.. but can anyone teach me the proper syntax of a "and" type query statement in XPath?

let's say I have a XML nodes
<node param1="one" param2="two"></node>
<node param1="one"></node>

to get both nodes, I can do a query with:
//node[@param1]

but is there any way that I can say
"only nodes that has BOTH param1 AND param2"?
I looked at the online tutorial but can't seem to figure it out.

Xpath For RSS
i asked this before but no luck getting an answer.. let me try again..

from yahoo RSS: this is how i can read the TITLE attribute using xpath in flash:
var thedesc = XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/media:text/p/a/img");
var thedesc_display = thedesc[0].attributes["title"]

i can read the TITLE when it is formatted like this in xml:
<p>
<a href="someLINK">
<img src="someSRC" align="left" height="87" width="130" alt="photo" title="DESCRIPTION OF THE IMAGE" border="0"/>
</a>
</p>

but, in xml they have the special characters. "<" is replaced with "<" and so on..
and when <P> is replaced with "<p>" i can't get to the title attribute using (this.firstChild, "/rss/channel/item/media:text/p/a/img").... and thus, can not retrive the TITLE data.

is there anything i can do in my flash code.. ??????? PLASE HELP.

XPath Help
I need some help using XPath. I can find a billion tutorials on how to use the functions, etc...but none on how to get it to work after downloading it (from xfactorstudio).

I can provide my code if needed, but basically I downloaded XPath, put it everywhere on my webserver and hard drive.

I import it:
import com.xfactorstudio.xml.xpath.*;

and use it according to the tutorials but get nothing!

I can parse the XML with using the standard firstChild, nextSibling, etc but want to use XPath to help out with the parsing.

Any help is greatly appreciated!! I'm pulling my hair out!

Xml :: Xpath
does anyone know of any flash xml class rewrites out there where someone may have rewritten the xml object to comply with xpath?

Where To Put XPath
Once I've downloaded XPath from xfactorstudio where do I put it?

I've looked for a 'Classes' folder in the application data folder for flash but its not there. I've created one but I still can't get XPath to work.

import com.xfactorstudio.xml.xpath.*;

var myDoc = new XPathDocument();
myDoc.onLoad = function(success){
.... do something .....
}

myDoc.load("

HELP WITH XPATH
trying to get an understanding of xpath
path ="/one/two/three';

var ArrayName:Array = XpathAPI.selectedNodeList(this.firstChild,path);

What trying to understand is this.firstChild - i understand this refers to current xml object - is it correct in assuming we navigating from the root node then apply the path structure in order to get to the nodes we after eg are we using this firstchild to anchor the path reference?

XPATH Help
I'm trying to write a little game in Flash that uses XML for persistent storage of questions and answers. Our e-learning developers can then reuse the game in various e-learning courses w/out having to do anything in Flash. I developed a "standard" XML format for handling questions and answers (and some additional stuff like hints and feedback), and used this XML format in a JavaScript-based game w/out any trouble (using XPATH to get the relevant data out of the XML file).

I'm having trouble getting the XPATH statements in ActionScript to work however.

In JavaScript, I used statements like:

questionsArray[z]["theText"]= questionNodes.item(z).selectSingleNode("theText").text;
questionsArray[z]["theHint"]= questionNodes.item(z).selectSingleNode("hint").text;

, etc, where questionNodes is the XML containing all the questions, to create an array of questions and answers.

When I try the same statements in ActionScript (using what I think would be the correct ActionScript syntax), I always get null results.

For example:
questionsArray[z]["theText"]= XPathAPI.selectSingleNode(questionNodes.item[z], "theText");
questionsArray[z]["theHint"]= XPathAPI.selectSingleNode(questionNodes.item[z], "hint");

For that matter, I can never get a trace to put out anything when using item[ ] syntax. For example, the following is undefined:

trace (questionNodes.item[1]);

Basically what I'm trying to do is create an array from the XML data, but I can't figure out how to "walk through" the XML data as I can in JS.

Any ideas? I know the XML is loading properly because I have some other XPATH statements that have worked..

Thanks for any advice! - Mike

Xpath For RSS
i asked this before but no luck getting an answer.. let me try again..

from yahoo RSS: this is how i can read the TITLE attribute using xpath in flash:
var thedesc = XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/media:text/p/a/img");
var thedesc_display = thedesc[0].attributes["title"]
i can read the TITLE when it is formatted like this in xml:
<p>
<a href="someLINK">
<img src="someSRC" align="left" height="87" width="130" alt="photo" title="DESCRIPTION OF THE IMAGE" border="0"/>
</a>
</p>
but, in xml they have the special characters. "<" is replaced with "<" and so on..
and when <P> is replaced with "<p>" i can't get to the title attribute using (this.firstChild, "/rss/channel/item/media:text/p/a/img").... and thus, can not retrive the TITLE data.

is there anything i can do in my flash code.. ??????? PLASE HELP.

Xpath Docs?
Hi,

is there anywhere on the web where i can find good documentation for xpath from xfactorstudio and as 2.0.

I'm a but stuck using it....

thx,
P

Flash, XML & XPATH
Hiya folks,

I am nearing the end of a project and just need to solve one part to complete it.

I have an XML file which contains lots of information abut all the various courses that my college offers. Each course has it’s own set of nodes and the main node for each course contains all the attributes used for things like title, search keywords, image, background colours etc etc.

EXAMPLE XML:


Code:

<course id="1" area="A Levels" bgcolor="E8E3BD" bgcolor2="ABAC39" code="Various" image="images/1.jpg" keywords="as, a2, a levels, a-levels, maths, science, social science, humanities, art and design, art, design, business" length="One/Two Years" level="3" location="Various Sites" name="AS and A2 levels" textcolor="FFFFFF" textcolor2="ABAC39">

<maintext>
<span class="subtitle">What’s it all about?</span>
A levels are normally a two year programme. In the first year you study AS subjects and when you have completed these, you move onto A2 subjects to achieve a full A level at the end of the second year.
<span class="subtitle">What does it involve?</span>
We have re-designed our full-time A level programme to support and enhance your career aspirations. We offer A level pathways in Science, Social Science, Humanities, Art and Design and Business. These provide packages of related subjects that link to broader degree and career routes.
</maintext>
</course>
I am using XPATH to loop through the XML and pull out all the courses that have a match in the keywords attribute to what the user enters in search field. I then display the results in a DataGrid component and when the user clicks on the result they want, I then call up a function that loads in all the correct course information.

SEARCH ACTIONSCRIPT:


Code:

// selects the nodes using ‘contains’ function of XPath
var query:String = "//course[contains(@keywords, "+"'"+term+"'"+")]";
myResults = XPath.selectNodes(myDoc, query);

// Converts myResults array of xml nodes to regular array
myDataSet = new Array();
for (var i = 0; i<myResults.length; i++) {
var name = XPath.selectNodes(myResults[i], "//@name");
var id = XPath.selectNodes(myResults[i], "//@id");
myDataSet.push({Name:name, ID:id});
}

//sends resulting array to result datagrid
this.dgSearchResults.dataProvider = myDataSet;
Now the trouble I am having is that what is getting stored in the myDataSet array and thus passed to the loadScreen function is not:


Quote:




AS and A2 levels, 1




BUT:


Quote:




Name=”AS and A2 levels”, ID=”1”




So the DataGrid ends up showing the results as:


Quote:




Name=”AS and A2 levels”
Name=”Foundation Art & Design”
Name=”Foundation Fashion Design”




Etc etc, and the value passed over to the loadScreen function with this bit of code:


Code:

var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {
loadScreen(myDataSet[evt_obj.target.selectedIndex].ID);
};
Is always something like ID=”1”, whereas I need it to simply be a numeric value like 1, 2, 78 etc.

I have tried creating a function to convert the values to what I need using toString() & substring() functions to strip off what I don’t want (i.e the name=” and the trailing “)


Code:

// attempt to strip off name=” bit
var csname2 = myDatSet[0].csname.toString().substring(6,0);
but it doesn’t work and csname2 is always undefined.

I also in another project (http://me.snickers.com) remember having to store the values using something like:


Code:
_global.navData.push({link:linkname_array[i].firstChild.nodeValue, file:linkfile_array[i].firstChild.nodeValue});
So that it stored the actual node value rather than the node & value together by pushing the value into the array object by referencing the nodeValue specifically..

I know I am using attributes here instead of nodes, and if I change my XML to use nodes for the ‘keywords’ and ‘ID’ rather than attributes, it works, but as there are over 200 courses, I really don’t want to go back to a more primitive and messy XML structure and can’t see that it isn’t possible to do it with attributes instead (plus having to change 200 courses back into nodes etc would take far to much time).

So can ANYONE please help me find a solution? I need to know how to either store just the attribute value in my myDataSet array, OR, how to strip off all the un-needed bits (i.e. ID=” & the trailing “) before I pass the data to the loadScreen function and the results DataGrid.

Any help would be really really appreciated and I can help by showing more files, code snippets etc if needed.

Hope to hear from someone soon…..

Cheers,

Drakash

XPath In Flash ..
Hi guys ive just started using XPath today ( but having a slight problem though getting attributes..any tips appreciated.. my XML document is as follows ...:



Code:
<CaseStudies>
<Store>
<imagegallery>
<image source="images/mask.jpg" />
<image source="images/juicer.jpg" />
<image source="images/wedding.jpg" />
</imagegallery>
</Store>
</CaseStudies>
and my flash is as follows:



Code:
import mx.xpath.XPathAPI;
var xmlData = new XML();

xmlData.ignoreWhite = true;


xmlData.onLoad = function(success) {
if (success) {
var companyPath:String = "/CaseStudies/Store/imagegallery";
var imageNode:Array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, companyPath);
trace(imageNode); //this traces out fine
trace(imageNode[0].attributes["source"]);//this give undefined
} else {
trace("error loading XML");
}
};

xmlData.load("data.xml");

As u can see above the first trace works fine and outputs:

<imagegallery>
<image source="images/mask.jpg" />
<image source="images/juicer.jpg" />
<image source="images/wedding.jpg" />
</imagegallery>


however

trace(imageNode[0].attributes["source"]);

seems to give undefined...

does anyone know why? Any help appreciated... cheers

Xpath Question - HELP
this is new for me- need some help here..

when im using:
_root.mytxt.htmlText=XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/title");
what should i do to view title 1 to 5 only from the xml file (currntly displays all titles)
for:
_root.mytxt.htmlText=XPathAPI.selectSingleNode(this.firstChild, "/rss/channel/item/title");
what should i do to (randomly) view the number 2 title from the xml file (currntly displays number 1 title only)

thank u so very much.

XPath And Actionscript2.0
Hello.. everybody,

[i] Can any one give me some information about XPath and Actionscript2.0 ??

[ii] I have, already, download " XPath4AS2 " from www.xfactorstudio.com.
But, I don't know where to put it (include it) my system so can use it, in my current as well as all projects.

[iii] If you can suggest me any site for (torials / codes), I will go through it.

Thanking you in advance.

Flash, XML & XPATH
Hiya folks,

I am nearing the end of a project and just need to solve one part to complete it.

I have an XML file which contains lots of information abut all the various courses that my college offers. Each course has it’s own set of nodes and the main node for each course contains all the attributes used for things like title, search keywords, image, background colours etc etc.

EXAMPLE XML:


Code:

<course id="1" area="A Levels" bgcolor="E8E3BD" bgcolor2="ABAC39" code="Various" image="images/1.jpg" keywords="as, a2, a levels, a-levels, maths, science, social science, humanities, art and design, art, design, business" length="One/Two Years" level="3" location="Various Sites" name="AS and A2 levels" textcolor="FFFFFF" textcolor2="ABAC39">

<maintext>
<span class="subtitle">What’s it all about?</span>
A levels are normally a two year programme. In the first year you study AS subjects and when you have completed these, you move onto A2 subjects to achieve a full A level at the end of the second year.
<span class="subtitle">What does it involve?</span>
We have re-designed our full-time A level programme to support and enhance your career aspirations. We offer A level pathways in Science, Social Science, Humanities, Art and Design and Business. These provide packages of related subjects that link to broader degree and career routes.
</maintext>
</course>
I am using XPATH to loop through the XML and pull out all the courses that have a match in the keywords attribute to what the user enters in search field. I then display the results in a DataGrid component and when the user clicks on the result they want, I then call up a function that loads in all the correct course information.

SEARCH ACTIONSCRIPT:


Code:

// selects the nodes using ‘contains’ function of XPath
var query:String = "//course[contains(@keywords, "+"'"+term+"'"+")]";
myResults = XPath.selectNodes(myDoc, query);

// Converts myResults array of xml nodes to regular array
myDataSet = new Array();
for (var i = 0; i<myResults.length; i++) {
var name = XPath.selectNodes(myResults[i], "//@name");
var id = XPath.selectNodes(myResults[i], "//@id");
myDataSet.push({Name:name, ID:id});
}

//sends resulting array to result datagrid
this.dgSearchResults.dataProvider = myDataSet;
Now the trouble I am having is that what is getting stored in the myDataSet array and thus passed to the loadScreen function is not:


Quote:




AS and A2 levels, 1




BUT:


Quote:




Name=”AS and A2 levels”, ID=”1”




So the DataGrid ends up showing the results as:


Quote:




Name=”AS and A2 levels”
Name=”Foundation Art & Design”
Name=”Foundation Fashion Design”




Etc etc, and the value passed over to the loadScreen function with this bit of code:


Code:

var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {
loadScreen(myDataSet[evt_obj.target.selectedIndex].ID);
};
Is always something like ID=”1”, whereas I need it to simply be a numeric value like 1, 2, 78 etc.

I have tried creating a function to convert the values to what I need using toString() & substring() functions to strip off what I don’t want (i.e the name=” and the trailing “)


Code:

// attempt to strip off name=” bit
var csname2 = myDatSet[0].csname.toString().substring(6,0);
but it doesn’t work and csname2 is always undefined.

I also in another project (http://me.snickers.com) remember having to store the values using something like:


Code:
_global.navData.push({link:linkname_array[i].firstChild.nodeValue, file:linkfile_array[i].firstChild.nodeValue});
So that it stored the actual node value rather than the node & value together by pushing the value into the array object by referencing the nodeValue specifically..

I know I am using attributes here instead of nodes, and if I change my XML to use nodes for the ‘keywords’ and ‘ID’ rather than attributes, it works, but as there are over 200 courses, I really don’t want to go back to a more primitive and messy XML structure and can’t see that it isn’t possible to do it with attributes instead (plus having to change 200 courses back into nodes etc would take far to much time).

So can ANYONE please help me find a solution? I need to know how to either store just the attribute value in my myDataSet array, OR, how to strip off all the un-needed bits (i.e. ID=” & the trailing “) before I pass the data to the loadScreen function and the results DataGrid.

Any help would be really really appreciated and I can help by showing more files, code snippets etc if needed.

Hope to hear from someone soon…..

Cheers,

Drakash

Using XPath In Flash
Hi guys ive just started using XPath today ( but having a slight problem though )..my XML document is as follows:



Code:
<CaseStudies>
<Store>
<imagegallery>
<image source="images/mask.jpg" />
<image source="images/juicer.jpg" />
<image source="images/wedding.jpg" />
</imagegallery>
</Store>
</CaseStudies>
and my flash is as follows:



Code:
import mx.xpath.XPathAPI;
var xmlData = new XML();

xmlData.ignoreWhite = true;


xmlData.onLoad = function(success) {
if (success) {
var companyPath:String = "/CaseStudies/Store/imagegallery";
var imageNode:Array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, companyPath);
trace(imageNode); //this traces out fine
trace(imageNode[0].attributes["source"]);//this give undefined
} else {
trace("error loading XML");
}
};

xmlData.load("data.xml");

As u can see above the first trace works fine and outputs:

<imagegallery>
<image source="images/mask.jpg" />
<image source="images/juicer.jpg" />
<image source="images/wedding.jpg" />
</imagegallery>


however

trace(imageNode[0].attributes["source"]);

seems to give undefined...

does anyone know why? Any help appreciated... cheers

XPath Integration
I'm just starting to play around with xml and xPath integration however I've hit a road block early. I've downloaded the as files off off X Factor Studio. I'm using the as1 files. Here's my xml:


PHP Code:



<?xml version="1.0" encoding="UTF-8" ?> 
- <trips>
- <trip name="Napa Valley">
  <description>Trip Description</description> 
  <cost>1095</cost> 
  <tapes>2</tapes> 
  <image>images/napa.jpg</image> 
  </trip>
- <trip name="Big Sur">
  <description>Trip Description</description> 
  <cost>1395</cost> 
  <tapes>2</tapes> 
  <image>images/bigsur.jpg</image> 
  </trip>
- <trip name="Grand Canyon">
  <description>Trip Description</description> 
  <cost>1111</cost> 
  <tapes>1</tapes> 
  <image>images/grandcanyon.jpg</image> 
  </trip>
-   </trips>



Here's my actionscript code:


ActionScript Code:
#include "XPath.as"
var myXML=new XML();
myXML.ignoreWhite=true;
myXML.onLoad=function(success){
    if(success){
        myFunction();
    }
}
myXML.load("trips.xml");
function myFunction(){
    trace (myXML.selectNodes("/trips/trip/@name"));
}

I'd like to see is an output array of the three trip locations but my trace comes up as undefined. I guess my first question is, am I including the proper file in the #include? Secondly, am I using the proper syntax to target the trip name attribute? Thanks in advance! I'm a novice when it comes to xml and should probably start from ground zero but I have time constraints and need to find out of this will be a viable solution.

XPATH Statement Help
I'm trying to write a little learning game in Flash, using XML as the data source, but I can't get any XPATH statements to work. I've written tons of XPATH against this structure in JavaScript, and the XPATH statements evaluate properly in XML Spy, but I always get "undefined" when I try to trace out the value of the XPATH statements in Flash 8.

I'll post a valid (to XML Spy, that is) XPATH statement and some sample code...

Thanks much for any help!

Mike









Attach Code

import mx.xpath.XPathAPI;
var theGameData:XML = new XML ();
theGameData.ignoreWhite=true;

theGameData.onLoad = function(success:Boolean) {
if (success) {
var theXPathString:String = "/interactionData/module/question[2]/theText";
trace (theXPathString);
var theDataString:String = XPathAPI.selectSingleNode(this.firstChild, theXPathString);
trace (theDataString.toString());
}
else {
trace ("SCREWED UP");
}
}
theGameData.load ("game_content_dev.xml");


And here is my XML Structure if it matters to anyone:


<interactionData>
<interactionUsage>
<scavengerHunt title="This appears in the title area of your interaction, if you have one" passingScore="70" passingMeasurment="percent">
<!-- reserved for other Scavenger Hunt specific info -->
</scavengerHunt>


<learningWheel title="This appears in the title area of your interaction, if you have one" passingScore="60" passingMeasurment="points">
<!-- reserved for other Learning Wheel specific info -->
</learningWheel>

</interactionUsage>

<module moduleNumber="2" moduleDescription="Your description of the module" moduleLabel="Your other language" moduleURL="http://highwire.highmark.com">
<question type="multipleChoice" moduleUsage="no" scavengerHuntUsage="yes" learningWheelUsage="yes">
<theText>What is the Capitol of PA?</theText>
<response correct="yes">Harrisburg</response>
<response correct="no">Pittsburgh</response>
<response correct="no">Philadelphia</response>
<feedbackCorrect>Good Job!</feedbackCorrect>
<feedbackIncorrect>You are a fool</feedbackIncorrect>
<hint>The smallest one.</hint>
<additionalInstructions>If you didn't get it right the first time, go back to school.</additionalInstructions>
</question>

<question type="trueFalse" moduleUsage="no" scavengerHuntUsage="yes" learningWheelUsage="yes">
<theText>Golf is cool.</theText>
<response correct="yes">True</response>
<response correct="no">False</response>
<feedbackCorrect>Good Job!</feedbackCorrect>
<feedbackIncorrect>Sorry, I decide the correct answers here!</feedbackIncorrect>
<hint>I personally like golf, and I'm in charge. So take a guess what the answer is.</hint>
<additionalInstructions></additionalInstructions>
</question>

<question type="multipleChoice" moduleUsage="no" scavengerHuntUsage="yes" learningWheelUsage="yes">
<theText>Which of the following is not a healthy choice?</theText>
<response correct="yes">Smoking</response>
<response correct="no">Eating fruits, nuts and veggies</response>
<response correct="no">Eating lean meat and low-fat dairy</response>
<feedbackCorrect>Good Job!</feedbackCorrect>
<feedbackIncorrect>Try again.</feedbackIncorrect>
<hint></hint>
<additionalInstructions></additionalInstructions>
</question>

<question type="multipleChoice" moduleUsage="no" scavengerHuntUsage="no" learningWheelUsage="yes">
<theText>This question shouldn't appear in a scavenger hunt.</theText>
<response correct="yes">Yikes!</response>
<response correct="no">Yikes!!</response>
<response correct="no">Yikes!!!</response>
<feedbackCorrect>Good Job!</feedbackCorrect>
<feedbackIncorrect>Try again.</feedbackIncorrect>
<hint></hint>
<additionalInstructions>If it does appear, there is a problem.</additionalInstructions>
</question>

</module>
</interactionData>

XPath API Woes
I'm trying to parse an XML document using the Actionscript 2 XPath API. In one place I am using this as my xpath:
presentation/content[@contentName='wellness']/section[@sectionName='Nutrition/Weight']'

It fails when I use a slash in the "sectionName" attribute, when I remove the slash in the XML file and change the xpath accordingly it works fine. This XML is being generated for me, so I really have no choice in the matter, the slash has to stay. Is there something I can do to get around this problem?

Xpath Sorting
hi all again


still working on a sort system in flash, i am fiddling around in xpath

yet, i stumble on an issue

lets say my xml is :

Code:
<xml>
<item client ="tolkien" id="1" work="whatever"etc etc </item>
<item client ="tolkien" id="1" work="whatever"etc etc </item>
<item client ="kirupa" id="2" work="whatever"etc etc </item>
</xml>
as you can see, i have 2 items for tolkien(which are responsible for 2 different works), 1 for kirupa (only 1 job)




now i want to show a list for al the clients, tough, i only want to show up
1 unique identity for every client
so in this case the output would be

found clients :
tolkien
kirupa


here is how i sort the clients with the mighty xpath
still it's outputwould be
tolkien
tolkien
kirupa


[code]
path = "/xml/item[@client]";
client_array = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path);
[code]

i hope this is , thanx in advance if anyone could help me out

Flash XML/XPATH
Code:
//Global XML Menu System
import mx.xpath.XPathAPI;
menuXML = new XML();
menuXML.load("nt_mc_menus.xml");
menuXML.ignoreWhite = true;
menuXML.onLoad = function(){
var path:String = "nutrilite/nature/whynutrilite/menu[@name='our history']";
arNodes = mx.xpath.XPathAPI.selectNodeList(menuXML.firstChild, path);
trace(arNodes.attributes["name"]);
}
Why is this tracing a value of undefined? I know it is returning in an array but this seems pretty simple...its picking off the correct node I cant seem to figure out how to grab the attribute value of name.

Xpath Issue?
I have this problem where my .swf is working fine on one host but doesnt work at another. The problem is that it doesnt want to show the variable txt. And the only thing i can think of is that the Xpath databinding doesnt work. Anyone got an idea what to do?


Code:
import mx.xpath.XPathAPI;
var news_xml:XML = new XML();
news_xml.ignoreWhite = true;
news_xml.load("readwrite/news.xml");
news_xml.onLoad = function(success:Boolean) {
trace("onload...");
if (success) {
trace("success...");
// Retrieve all the entry nodes
var thePath:String = "/*/news/entry";
var entryArray:Array = XPathAPI.selectNodeList(this, thePath);

//Build an array for sorting the entry nodes
var entrySortArray:Array = new Array();
var sortObj:Object;
trace("This many nodes were found: " + entryArray.length);
for(var i:Number = 0; i < entryArray.length; i++){
sortObj = new Object();
sortObj.title = entryArray[i].childNodes[0].firstChild.toString();
sortObj.tid = entryArray[i].childNodes[4].firstChild.toString();
sortObj.tidSec = getTIDSeconds(sortObj.tid); //convert string so you can do a numeric sort
sortObj.dateTime = entryArray[i].attributes.date;
entrySortArray.push(sortObj);
}

//sort the array
entrySortArray.sortOn("tidSec", Array.NUMERIC); //sorts ascending //
//build text for display
var txt:String = "";
for(var i:Number = 0; i < entrySortArray.length; i++){
if(txt != "") txt += "
";
txt += entrySortArray[i].title + " " + entrySortArray[i].tid; //+ " (" + entrySortArray[i].dateTime + ")";
}
trace("txt is: " + txt);
//display text
content_txt.htmlText = "poäng" + txt;

} else {
trace("error loading XML");
content_txt.htmlText = "Error i XMLladdningen";
}
};

function getTIDSeconds(tid:String):Number{
var rv:Number = 0;
var minutes:Number = 0;
var seconds:Number = 0;

var pos:Number = tid.indexOf(":");
if(pos < 0){
minutes = Number(tid);
}
else{
minutes = Number(tid.slice(0, pos));
seconds = Number(tid.substr(pos+1));
}
rv = minutes * 100 + seconds;

//trace("getTIDSeconds for " + tid + " is " + rv);
return(rv);
}

Xpath Question
this is new for me- need some help here..

when im using:
_root.mytxt.htmlText=XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/title");
what should i do to view title 1 to 5 only from the xml file (currntly displays all titles)

for:
_root.mytxt.htmlText=XPathAPI.selectSingleNode(this.firstChild, "/rss/channel/item/title");
what should i do to (randomly) view the number 2 title from the xml file (currntly displays number 1 title only)

thank u so very much.

RSS Into Flash Using XPATH
this is from yahoo RSS:


Code:

<media:content url="someURL" type="image/jpeg" height="87" width="130" />
<media:text type="html">
<p>
<a href="someLINK">
<img src="someSRC" align="left" height="87" width="130" alt="photo" title="DESCRIPTION OF THE IMAGE" border="0"/>
</a>
</p>
<br clear="all"/>
</media:text>
is there anyway i can get the value of the image title (title="DESCRIPTION OF THE IMAGE") into flash. this is how im getting the image from media:content node:
thetitle = XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/media:content");
thetitle_url = thetitle[RanNum].attributes["url"];

similarly, i can get into the media:text node using:
thedesc = XPathAPI.selectNodeList(this.firstChild, "/rss/channel/item/media:text");

but is there anyway i can read the value of the image title in flash ?? please help.

Flash & Xpath
I want with actionscript to find an Attribute of a tag at a xml file.
How Can I do it?

MX 2004 XPath
Hi,

Trying desperatly to convert a Firefly based application to MX PRO 2004, but can't find any documentation for the xpathAPI ... I HAVE found the XPATH supportd syntax list for the DataBinding Component, but WHERE is the documentation for the methods of the API...???

Google is silent on this, other than a sprinkiling of similar questions...

Grrrrrrr.

www.freesome.com
    Digital Soma

AS2 - XPath Usage
Hi all,
i've this XML file:


HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<download>
<elemento>
<id>
<![CDATA[id_download]]>
</id>
<titolo>
<![CDATA[Download 01]]>
</titolo>
<descrizione>
<![CDATA[Vestibulum libero nisl]]>
</descrizione>
<file>
<![CDATA[download01.swf]]>
</file>
<data>
<![CDATA[20071210]]>
</data>
<categoria>
<![CDATA[1]]>
</categoria>
<sottocategoria>
<![CDATA[]]>
</sottocategoria>
</elemento>
<elemento>
<id>
<![CDATA[id_download]]>
</id>
<titolo>
<![CDATA[Download 01]]>
</titolo>
<descrizione>
<![CDATA[Vestibulum libero nisl]]>
</descrizione>
<file>
<![CDATA[download01.swf]]>
</file>
<data>
<![CDATA[20071210]]>
</data>
<categoria>
<![CDATA[1]]>
</categoria>
<sottocategoria>
<![CDATA[]]>
</sottocategoria>
</elemento>
</download>
I want to be able to read the data after parsing the file, using this syntax:

Code:
arItems[i].id
arItems[i].titolo
How can i read the node values using Flash built-in XPath?

Thanks to all

[as 1, XML, XPATH, CSS] My CSS Doesn't Work ?
Hi people,

I have the following problem:

I have an .fla and .swf that loads a .xml in several tekstfields. Also serveral other variables for things that I need.

Everything works so far but the CSS doesn't !!! The CSS is external.
I loaded the .xml through an XPATH script but that isn't the problem with the loading of the CSS I think...

For a better see an explanation of my problem see my .fla and so on, on:
http://www.rovecon.nl/xpath.rar

I hope you can help me, because I am really stuck !

I commented the loading of the CSS in my script, I began to try to apply my CSS to my headline at first...

Using Contains Comparison In Mx.xpath.XPathAPI
Is it possible to use something like this using m.xpath.XPathAPI parser

var recordPath:String = "/RECORDLIST/RECORDS/RECORD[contains(@name,'192.COM')]";
title_array = mx.xpath.XPathAPI.selectNodeList(codeFeed.firstChi ld, recordPath);

I am trying to match the values in the attribute name that contain "192.com"

This should be possible, but am not able to get any examples or documentation could someone help?

Thanks
KashSen

Xpath Help (get Node Position)
say I have some xml:


Code:
<xml>
<books>
<book id="1984">
<book id="The Hobbit">
<book id="Catch 22">
</books>
</xml>


I use an xPath query to get "The Hobbit". Cool. That works. But is there a way to tell me that's the second item in book nodes (i.e. myBooks[1])?

Xpath For Flash Sort
hi, is there a way to sort by name a Xpath query ? my code :


PHP Code:



var query:String = "//projectItem";
    var result:Object = XPath.selectNodes(_root.getWorksObj, query);
    for (inc; inc<len; inc++) {
    // BUILD PROJECT CORE DATA STRUCT
        var temp_data:Object = new Object();
        temp_data.id = XPath.selectNodes(result[inc], "./id")[0].firstChild.nodeValue;
        temp_data.client = XPath.selectNodes(result[inc], "./client")[0].firstChild.nodeValue;
        temp_data.project = XPath.selectNodes(result[inc], "./project")[0].firstChild.nodeValue;
        temp_data.types = XPath.selectNodes(result[inc], "./type")[0].firstChild.nodeValue;
        temp_data.date = XPath.selectNodes(result[inc], "./date")[0].firstChild.nodeValue;
        temp_data.thumbnail = XPath.selectNodes(result[inc], "./thumbnail")[0].firstChild.nodeValue;
        temp_data.info = XPath.selectNodes(result[inc], "./info")[0].firstChild.nodeValue;
        temp_data.elink = XPath.selectNodes(result[inc], "./elink")[0].firstChild.nodeValue;
        temp_data.images = XPath.selectNodes(result[inc], "./images")[0].firstChild.nodeValue;
        temp_data.video = XPath.selectNodes(result[inc], "./video")[0].firstChild.nodeValue;
        temp_data.keywords = XPath.selectNodes(result[inc], "./keywords")[0].firstChild.nodeValue;


Xpath-loop Through Attributes
Code:
for (var i = 0; i<mx.xpath.XPathAPI.selectNodeList(xNav.firstChild, xmlpath).length; i++) {
trace(mx.xpath.XPathAPI.selectSingleNode(xNav.firstChild, xmlpath).attributes["label"]);
aVariables.push(mx.xpath.XPathAPI.selectSingleNode(xNav.firstChild, xmlpath).attributes["label"]);

}
As you can see Im trying to loop through the attributes not just the nodes. It is only giving me the first since using the method selectSingleNode is the only one which seems to give attribute values.

I will have to go in and do an old style loop otherwise.
thanks

Silly Xpath Problems
I'm sure it is a result of staying up too late but I just can't seem to parse this xml out correctly and cannot figure out why it does not work.

The xml:


Code:
<?xml version="1.0"?>
<news>
<line>
<p class="leadin">- ST. CATHERINES, ONTARIO, April 10, 2007</p>
<p class="italic">blah blah blah</p><br/><br/>
</line>
<line>
<p class="leadin">- LONDON, ONTARIO, March 09, 2007</p><br/>
<p class="italic">blah blah blahblah blah blahblah blah blah</p><br/>
</line>
</line>
</news>

The actionscript I am using to get at the xml:


Code:
function LoadNewsXml(){
//get news array

var newsXML:XML = new XML();

newsXML.ignoreWhite = true;
newsXML.onLoad = function(success) {
if (success) {
newsArr = XPathAPI.selectNodeList(this.firstChild, "news/line");
newsStr = "";
trace("News gotten");
trace("newsArr[0]="+newsArr[0]);
trace("newsArr.length="+newsArr.length);

for (i=0;i<newsArr.length;i++){
newsStr += newsArr[i].firstChild.nodeValue;
}
trace("newsStr="+newsStr);
LoadAlumniXml()
}
};
newsXML.load("../text/news.xml");
}

The results:


News gotten
newsArr[0]=<line><p class="leadin">- ST. CATHERINES, ONTARIO, April 10, 2007</p><p class="italic">blah blah blah</p><br /><br /></line>
newsArr.length=4
newsStr=nullnullnullnull

What I want of course is for newsStr to have concantenated values of the line nodes sans the <line> tags but I have no idea why it is not returning those results. I am sure it is something stupid I am missing and would appreciate someone pointing me out the error(s) of my ways.

V

XPath Attribute Syntax
Hello,

I recently found some threads on this forum where was praising XPath, so I started playing around with it. I find it very, very cool.

Im currenntly having issues with a small syntax thing that hopefully somebody can help me out with.


I've tried this.

trace(someXML.selectNodes("/entry/menu/@folder"));

this results in an array like this: folder="about",folder="works",folder="contact"


I've also tried this

listOfMenuitems = someXML.selectNodes("/entry/menu");
trace(listOfMenuitems[0].attribute());

which results in this: folder="about"



What I am trying to achieve is to extract the VALUE or VALUES of the particular attributes. Something like this:
about,works,contact

I've tried the reference, but I am obviously not getting this detail.

Thank you very much for anything that might help me in my quest.

Problem With XPath & Strings
Hi

I have a problem with getting a string out of XPath which has a line break in it

Say i have a node which has

Code:
<nodename>abc
def</nodename>
If i return it via
Code:
testvar = XPath.selectNodes(this,"//nodename/text()")
If i then apply this to a dynamic textField i get "abc
def"
It doesn't recognise the


When i 1st bring it in if i get
Code:
trace(typeof testvar)
it returns object so i convert this to a string via toString(); and strict data typing

I have tried doing it as html and including <br /> tags & <![CDATA[<br />]]>, etc... but to no avail

If anyone has any idea i would be greatful

Cheers
Andy

XML, XPath, Looping, And MovieClips
Hi guys,

I'm trying to do somehting in AS, and I'm totally lost. Bascally, what I would like to do is extract data from and XML file (that part is working), and then tak all the child nodes of a Parent and output them formatted into a table. (This is suppose to create a timeleinme in a a Flash application I'm working on.)

The XML would look something like this:

<years>
<year value="2000">This happened.</year>
<year value="2001">That happened.</year>
<year value="2002">More happened.</year>
<year value="2003">Nothing happened.</year>
</years>

Using XPath, I want to taake each of those year s and return a table element that looks somehting like this:

------------------------------------
|2000 |2001
------------------------------------
|This happened.| That happened.
------------------------------------

If anyone has any ideas about where to start with this, I'd be very greatful.

Thanks!

Xpath Next/prev Button?
Hey!

Got my XML thing to work... almost. Hehe. But my next/previous buttons doesnt work. I've been trying to type different kind of code but with no luck. So... As you can see "sCase" is the one that tells flash what node it should look at. If I trace out aURL then I can see that there are the correct number of pictures to that moment, also correct filnames. But how do I get my next and previous buttons to work?


Code:
//Meny
var sCase:String = 'Göteborg';
laddaXML(sCase);

mcKarlskrona.onRelease = function(sCase) {
sCase = 'Karlskrona';
laddaXML(sCase);
}
mcGbg.onRelease = function(sCase) {
sCase = 'Göteborg';
laddaXML(sCase);
}

//XML inladdning
function laddaXML(sCase) {
import com.xfactorstudio.xml.xpath.*;
var aURL:Array = new Array();
var nBildnr:Number;

myDoc = new XML();
myDoc.ignoreWhite = true;
myDoc.onLoad = function(){
var products = XPath.selectNodes(this,"/slideshow/foton[@location='" +sCase +"']/photo@url");
for(i=0;i<products.length;i++) {
aURL.push(products[i]);
}
mcHolder.loadMovie(aURL[0]);
nBildnr = 0;
}
myDoc.load("slideshow.xml");
}
//

//Navigering i slideshow
btnNext.onRelease = function() {
mcHolder.loadMovie(aURL.push("/following-sibling"));
}

btnPrevious.onRelease = function() {
if(nBildnr > 0) {
nBildnr--;
mcHolder.loadMovie(aURL++);
}
}

//

//Preloader
this.onEnterFrame = function() {
nFilstorlek = mcHolder.getBytesTotal();
nLaddat = mcHolder.getBytesLoaded();
nProcent = Math.round(100*nLaddat/nFilstorlek);
mcDragOver._visible = true;
txtProcent._visible = true;
if (nLaddat != nFilstorlek) {
mcDragOver._yscale = nProcent*100;
txtProcent.text = nProcent + '%';
} else {
mcDragOver._visible = false;
txtProcent._visible = false;
}
};
//

Xpath And Global Array
Hi there I am new to flash and xml intergration and have been using xpath to retrive data from my xml object, this is all fine. But what I want is this information to be avalable to all functions not just the one it is created in. This is where it stops working



a snippet of the code i am using is



function tabmanuname()
{

// assign selected XML content to array titleArray
sectionNames = XPathAPI.selectNodeList(my_xml.firstChild, "/broadcast/story/*");


}



now this works fine as an array if I access the content within this functions such as



trace(sectionNames[1]);



but if i try this from any other function it says undifined



I have tried creating a global array but can get it to work, i need the content of "sectionNames" array to be avalable to all



please somone help this is driving me nuts



thanks all



anymore info just ask



lee

Flash & XML Help (maybe XPATH Problem)
Hiya folks,

I am nearing the end of a project and just need to solve one part to complete it.

I have an XML file which contains lots of information abut all the various courses that my college offers. Each course has it’s own set of nodes and the main node for each course contains all the attributes used for things like title, search keywords, image, background colours etc etc.

EXAMPLE XML:


Code:

<course id="1" area="A Levels" bgcolor="E8E3BD" bgcolor2="ABAC39" code="Various" image="images/1.jpg" keywords="as, a2, a levels, a-levels, maths, science, social science, humanities, art and design, art, design, business" length="One/Two Years" level="3" location="Various Sites" name="AS and A2 levels" textcolor="FFFFFF" textcolor2="ABAC39">
<maintext>
<span class="subtitle">What’s it all about?</span>
A levels are normally a two year programme. In the first year you study AS subjects and when you have completed these, you move onto A2 subjects to achieve a full A level at the end of the second year.
<span class="subtitle">What does it involve?</span>
We have re-designed our full-time A level programme to support and enhance your career aspirations. We offer A level pathways in Science, Social Science, Humanities, Art and Design and Business. These provide packages of related subjects that link to broader degree and career routes.
</maintext>
</course>
I am using XPATH to loop through the XML and pull out all the courses that have a match in the keywords attribute to what the user enters in search field. I then display the results in a DataGrid component and when the user clicks on the result they want, I then call up a function that loads in all the correct course information.

SEARCH ACTIONSCRIPT:


Code:

// selects the nodes using ‘contains’ function of XPath
var query:String = "//course[contains(@keywords, "+"'"+term+"'"+")]";

myResults = XPath.selectNodes(myDoc, query);

// Converts myResults array of xml nodes to regular array
myDataSet = new Array();
for (var i = 0; i<myResults.length; i++) {
var name = XPath.selectNodes(myResults[i], "//@name");
var id = XPath.selectNodes(myResults[i], "//@id");
myDataSet.push({Name:name, ID:id});
}

//sends resulting array to result datagrid
this.dgSearchResults.dataProvider = myDataSet;
Now the trouble I am having is that what is getting stored in the myDataSet array and thus passed to the loadScreen function is not:


Quote:




AS and A2 levels, 1





BUT:


Quote:




Name=”AS and A2 levels”, ID=”1”






So the DataGrid ends up showing the results as:


Quote:




Name=”AS and A2 levels”
Name=”Foundation Art & Design”
Name=”Foundation Fashion Design”






Etc etc, and the value passed over to the loadScreen function with this bit of code:


Code:

var dgListener:Object = new Object();
dgListener.change = function(evt_obj:Object) {
loadScreen(myDataSet[evt_obj.target.selectedIndex].ID);
};
Is always something like ID=”1”, whereas I need it to simply be a numeric value like 1, 2, 78 etc.

I have tried creating a function to convert the values to what I need using toString() & substring() functions to strip off what I don’t want (i.e the name=” and the trailing “)


Code:

// attempt to strip off name=” bit
var csname2 = myDatSet[0].csname.toString().substring(6,0);
but it doesn’t work and csname2 is always undefined.

I also in another project (http://me.snickers.com) remember having to store the values using something like:


Code:
_global.navData.push({link:linkname_array[i].firstChild.nodeValue, file:linkfile_array[i].firstChild.nodeValue});


So that it stored the actual node value rather than the node & value together by pushing the value into the array object by referencing the nodeValue specifically..


I know I am using attributes here instead of nodes, and if I change my XML to use nodes for the ‘keywords’ and ‘ID’ rather than attributes, it works, but as there are over 200 courses, I really don’t want to go back to a more primitive and messy XML structure and can’t see that it isn’t possible to do it with attributes instead (plus having to change 200 courses back into nodes etc would take far to much time).

So can ANYONE please help me find a solution? I just need to know how to either store just the attribute value in my myDataSet array, OR, how to strip off all the un-needed bits (i.e. ID=” & the trailing “) before I pass the data to the loadScreen function and the results DataGrid.

Any help would be really really appreciated and I can help by showing more files, code snippets etc if needed.

Hope to hear from someone soon…..

Cheers,

Drakash

Flash/XPath Question
Forgive me for being an idiot, but it's been so long since I've done much in flash that I'm a bit rusty. Something tells me I used to know how ot od thhis, but for the life of me, I can't remmeber.

I'm building an application in flash (using the XPath libraries from www.xfactorstudio.com) for customers to design their own custom computer. The plan is to have several "base" systems that can be loaded into the app then they will be able to customize the system by selecting different components from menus, etc. All the data will be stored in XML files, a different file for each type of component (that will then include details for each variation of said component that we carry), and a set of XML files for the 'base" systems, and finally, one controller XML file to tell the app which files belong to which groups, etc.

All of that is probalby more info than you need to answer this question, but hey, I'm really excited about building this.

Sooo, anyway, on to the problem. Let me give you an example of my XML for a base computer system.


Code:
<computer>
<info>
<name>Test Computer One</name>
<base>200</base>
<image>images/test.jpg</image>
</info>
<hardware>
<motherboard>
<name>MB 1</name>
<price>100</price>
<specs>MB Specs</specs>
</motherboard>
</hardware>
</computer>
Alright, so now I'm grabbing the XML data in Flash like so....


Code:
pc.onLoad = function() {
pcInfo = pc.selectNodes("//info");
trace(pcInfo);
}
This returns:


Code:
<info><name>Test Computer One</name><base>200</base><image>images/test.jpg</image></info>
Makes sense, right?

Now, how do I pull just one element out of that, i.e. "name" ?

I don't want to have to go grabbing them all indivudally, like so


Code:
pcName = pc.selectNodes("//info/name");
pcBase = pc.selectNodes("//info/base");
pcImage = pc.selectNodes("//info/name");
I'm trying to avoid that... I would much rather just grab the data out of a parent array, i.e. "pcInfo" as needed.

But there's only one problem.....

How?

Using XPath To Get 'attribute' Values
I think I'm possibly being dumb, but when I call an attribute value using something like  //item/enclosure/@url  
I always get back the whole thing, including the equals sign and quotes  eg:  ="http://etc.etc.etc.mp3"
 
Is there not a way for me to just get the url value, without the sign and quotes (in this example), or would I just have to strip out the chars I dont want?
 
 
seems weird, if I have to.

tia

Strange Xml Problem (using Xpath)
hi there again,

this is painfull, i've manged to do this without anytrouble in the past
for various clients, and the irony of it all, now that i find time to build my portfolio i get this strangeness..

running a xml file comming from a database.

i get this output in flash (this resembles 1 item) :
Code:

<fol_port_id='40' fol_port_name="Resonant Evil" fol_port_jobtype="picturedisk" fol_port_client="Outbreak Recordings" fol_port_img="resevil-picturedisk.jpg" />

every info is correct placed into a variable name as such:
Code:

trace("start for item : "+j);
trace("job id : "+nodesPort[j].attributes.fol_port_id);
trace("job name : "+nodesPort[j].attributes.fol_port_name);
trace("picture : "+nodesPort[j].attributes.fol_port_img);
trace("client : "+nodesPort[j].attributes.fol_port_client);
trace("job type : "+nodesPort[j].attributes.fol_port_jobtype);
trace("end for item : "+j + "_______________");


i trace every thing correctly,
>>> only for the fol_port_id i get an undefined output. this totally doesn't make sense to me cuz i can clearly trace the other attributes (as being 40 in this case).

i use xpath API built in flash.
Code:

path = "/list/*";
nodesPort = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path);


my xml is build like this gathering the info from a simple select * querry in php

Code:

<list>
<fol_port_id='$fol_port_id' fol_port_name="$fol_port_name" fol_port_jobtype="$picturedisk" fol_port_client="$fol_port_client" fol_port_img="$rfol_port_img" />
</list>


am i tired and do i miss something? this worked perfect until today. i just can't get hold on it. this method was very comfortable to me cuz i was able to update variables in a few clicks, sadly enough there seems to be a problem.

any help / or a better way is greatly appreciated.

Xpath : Sort Question
hi gang

i am working on a quite indepth search/sort thing in flash pro 8 .

works absolutly great

yet i stumble on a problem

lets say my xml is :

Code:

<xml>
<item format="book" client="tolkien">LORD OF THE RINGS</item>
<item format="movie" client="tolkien">LOTR THE MOVIE</item>
<item format="book" client="friendsofed">AS 2.0</item>
</xml>


so as you can see i made some attributes to specify my sorting in depth, as far as i want.

but how to show lets say my client tolkien but only ONCE.
lets say i need a list of all my client names, i don't want to show 5 times tolkien if i worked 5 times for him but only once.
i know about unique id's for this stuff, but it still shows up the total list of clients
i hope i am clear

Select Attribute With Xpath Question.
Hi

I have an xml file where a element called current is set if the leaf is the current video playing.

the path to this node in xpath is

/node/node/node/leaf/@current

however what i would like to do it select the id element from the leaf that contains the current element. But i can't quite get the correct syntax. I have tried things along the lines of this but no dice.

/node/node/node/leaf/@id[@current]
/node/node/node/leaf//@id[@current]
/node/node/node/leaf/id[@current]
/node/node/node/leaf//id[@current]

Can anyone guide me in the right direction?

Cheers

Gareth

Problem With XFactor XPATH Api Statement
Okay, given the little XML snippet below, the following XPATH statement using XFactor Studio's XPATH works fine if both <question>'s are in the same <topic>, but as soon as I introduce multiple <topic> nodes, I get jumbled results.

_global.questionsArrayAll = XPath.selectNodes(theGameData.firstChild, "//question[@gameUsage='yes']");

Does anything jump out at anyone as being wrong? I thought // always caused a "start at root and get anything at any level" in XPATH...



<topic>
<question type="multipleChoice" gameUsage="yes">
<theText>What color is blue?</theText>
<response correct="yes">Blue</response>
<response correct="no">Red</response>
<response correct="no">Green</response>
<feedbackCorrect>Right!</feedbackCorrect>
<feedbackIncorrect>Not quite. Blue is blue</feedbackIncorrect>
<hint>Not red or green, that is for sure!</hint>
</question>
</topic>

<topic>

<question type="multipleChoice" gameUsage="yes">
<theText>What number is 10?</theText>
<response correct="yes">10</response>
<response correct="no">9</response>
<response correct="no">11</response>
<feedbackCorrect>Right!</feedbackCorrect>
<feedbackIncorrect>Not quite. It is 10</feedbackIncorrect>
<hint>Between 9 and 11</hint>
</question>

</topic>

Xpath Case Insensitive Search?
Hello,

I have succesfully implemented Xpath from Xfactor (http://www.xfactorstudio.com). I can do a search with the function "contains".

The only thing with this is that the search is case sensitive. So you need to do a exact search. I've read some about the "translate" function but don't know if all the output is translated to upper-case or lower-case or not. I also don't knowexactly how to use the translate function of Xpath.

What is the best solution to have a case INsensitive search with Xpath?

Can anybody help me out? I'm not that familiar with Xpath.


ActionScript Code:
import com.xfactorstudio.xml.xpath.*;

var products = new Array();
myDoc = new XPathDocument();
myDoc.onLoad = function(){
        details = "XML successfull loaded";
}
myDoc.load("dealers.xml");

details = "Loading...";

function fillMylist(){
        details = "done searching";
        trace(products);
        for (var i=0; i<products.length; i++) {
                // these changes to the data provider will be broadcast to the list
                mylist.addItem({label: products[i].attributes.naam,
                                            data:  i});
        }
}

function search(searchString:String):Void{
        details = "searching... " + searchString + " in " + _root.selector.selectedItem.label;
        mylist.removeAll();
        _root.products = XPath.selectNodes(_root.myDoc,"/dealer/dealer[contains(@" + _root.selector.selectedItem.label + ", '" + searchString + "')]");
        fillMylist();
}

function showdetails():Void{
        details = _root.products[_root.mylist.selectedItem.data].attributes.dealercode + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.naam + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.straat + " " + _root.products[_root.mylist.selectedItem.data].attributes.huisnr + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.postcodenr + "|" + _root.products[_root.mylist.selectedItem.data].attributes.postcodeletters + " " + _root.products[_root.mylist.selectedItem.data].attributes.plaats + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.telefoon + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.fax + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.url + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.dealerid + "";
        details = details + _root.products[_root.mylist.selectedItem.data].attributes.provincie + "";
}

thanks!

Celar

Querying With XPath - Using Xfactorstudio's AS2 Class
hiya,
i am having trouble using xfactor's example search text to return an array of nodes that match a criteria...here is my shortened xml file (from a .NET webservice)


ActionScript Code:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<get_Navigation_ForFlashResponse xmlns="http://www.myurl.com/webservices/">
<get_Navigation_ForFlashResult>

<Navigation>
   <title>Admin</title>
   <parent_id>0</parent_id>
</Navigation>

<Navigation>
   <title>Some Area</title>
   <parent_id>0</parent_id>
</Navigation>

</get_Navigation_ForFlashResult>
</get_Navigation_ForFlashResponse>
</soap:Body>
</soap:Envelope>

Now this xml loads in fine to flash, but when i try to query it with:


ActionScript Code:
//dp is the xml object
var nav:Array = XPath.selectNodes(dp,"//Navigation[./parent_id=0]");

it returns a length of 0. In the actual xml file i have lots more navigation items with parent_id's of 0, but i shortened it for this example. Does anyone have any clue? I have also tried various other querying methods like the following:


ActionScript Code:
//returns length of 0
var nav:Array = XPath.selectNodes(dp.firstChild.firstChild.firstChild,"//Navigation/*[parent_id="0"]
//returns length of 0
var nav_result = XPath.selectNodes(dp.firstChild.firstChild.firstChild,"/get_Navigation_ForFlashResult/Navigation[./parent_id=0]");

nothing...no luck at all. *sigh* Xfactor's example says that to return nodes with a child node of "price" with a value of 5 (<price>5</price>), do this:

ActionScript Code:
XPath.selectNodes(myXml,"/products/product[./price > 5]");

any help or crazy ideas would be incredibly welcome...! thanks ahead of time!!

Problem With XFactor XPATH Api Statement
Given the little XML snippet below (attached code), the following XPATH statement using XFactor Studio's XPATH works fine if both <question>'s are in the same <topic>, but as soon as I introduce multiple <topic> nodes, I get jumbled results.

_global.questionsArrayAll = XPath.selectNodes(theGameData.firstChild, "//question[@gameUsage='yes']");

Does anything jump out at anyone as being wrong? I thought // always caused a "start at root and get anything at any level" in XPATH...









Attach Code

<topic>
<question type="multipleChoice" gameUsage="yes">
<theText>What color is blue?</theText>
<response correct="yes">Blue</response>
<response correct="no">Red</response>
<response correct="no">Green</response>
<feedbackCorrect>Right!</feedbackCorrect>
<feedbackIncorrect>Not quite. Blue is blue</feedbackIncorrect>
<hint>Not red or green, that is for sure!</hint>
</question>
</topic>

<topic>

<question type="multipleChoice" gameUsage="yes">
<theText>What number is 10?</theText>
<response correct="yes">10</response>
<response correct="no">9</response>
<response correct="no">11</response>
<feedbackCorrect>Right!</feedbackCorrect>
<feedbackIncorrect>Not quite. It is 10</feedbackIncorrect>
<hint>Between 9 and 11</hint>
</question>

</topic>

XML/XPath Data Type Issue...
ok this is starting to bug me...

Basically, I'm loading my XML data into flash then parsing it using XPath so I can easily access node based on the their name etc.

structure is like this:

<doc>
<section1>
<info></info>
<info></info>
</section1>
<section2>
<info></info>
<info></info>
</section2>
<section3>
<info></info>
<info></info>
</section3>
etc.. etc..
</doc>


I loop through and create arrays for all the sections attributes and info values sorta like so:

tempNumExtraImagesArray[x] = XPath.selectNodes(this,"/string/cell"+x+"/num_extra_photos/text()");

this succeeds in grabbing the values but when I go to evaluate this array later in the loop, like this:

if(tempNumExtraImagesArray[x] > 0){
trace("somethingorother");
}

it chokes!

I've tried forcing the array values to numbers like so:

tempNumExtraImagesArray[x] = Number(XPath.selectNodes(this,"/string/cell"+x+"/num_extra_photos/text()"));

and when I trace the array it pumps out NaN. Maybe I've been staring at the screen too long but it's driving me nuts. If anyone could shed some light it would help save what little hair I already have.

Thanks!

XFactorstudio XPath Requires Full URL To Load?
I just did a project that called in a static hand-edited XML file to render some content in a Flash piece. I decided to use XFactorstudio's XPath implementation and try it out. Much to my surprise, the day I was trying to launch the project, I could not load the XML properly from a server, even though it worked fine when tested on a local Flash player client.

Typically, I use flashvars in my OBJECT and EMBED tags to leave me the option of changing the relative path to an XML file in one of my projects. I then just load the flashvar into the project. It keeps it from being hardcoded into the Flash interactive.

This time, I used a relative path (urlencoded) in the flashvar, and nothing happened. The XML wouldn't load. It WAS on a phsyically different server, but the relative path should've worked. Instead, the only way I could load the XML using Xfactostudio's XPath implementation was to use the FULL absolute URL in the flashvar (e.g. http://www.website.com/xmlfile.xml).

Any ideas why this may have happened? Is that something that happens with XFactorstudio's XPath implementation?

Thanks,
IronChefMorimoto

Copyright © 2005-08 www.BigResource.com, All rights reserved