Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : XPath API falty??


SilicoNblOOd
5/4/2004 10:31:40 PM
I need to access an attribute in the XML connectors scheme, how do i do that?
the xml is for example
<main>
________<node myAttr="one">bla bla bla</node1>
________<node myAttr="two">bla bla bla</node2>
</main>
+++++++++++++++++++++
Apparently, the syntax /main/node[a] DOES NOT WORK??? How do i refer to
elements in a list?
and, of course, there is no reference for the syntax to access the attribute
myAttr?
HELP
SilicoNblOOd
5/5/2004 6:31:13 PM
egorlebowski
5/5/2004 7:27:49 PM
XML (ie: "test.xml"):
<main>
<node myAttr="one">bla bla bla</node>
<node myAttr="two">bla bla bla</node>
</main>

Flash:
myXML=new XML();
myXML.ignoreWhite=true;
myXML.onLoad=function(success){
if(success){
mainNode=this.firstChild;
children=mainNode.childNodes;
for(var c=0;c<children.length;c++){
var attr=children[c].attributes.myAttr;
var nodeVal=children[c].firstChild.toString();
trace("Child Node: "+c+" myAttr= "+attr+" node Value= "+nodeVal);
}
}
}
myXML.load("test.xml");

Jan-Paul K.
5/5/2004 7:45:09 PM
maybe you should take a look at the XPath syntax:

[L=http://www.w3schools.com/xpath/xpath_syntax.asp]http://www.w3schools.com/xpat
h/xpath_syntax.asp[/L]

so for you problem your syntax to get the element nodes as an array would be:
//main/node

to get a certain node with an attribute value of "one" you would use:
//main/node[@myAttr='one']

to get all values of the attribute myAttr you would use:
//main/node/@myAttr
or simply
//@myAttr
SilicoNblOOd
5/5/2004 8:43:32 PM
IT DOES NOT WORK!
AddThis Social Bookmark Button