parse xml array

  • taufiq
  • Newbie
  • Newbie
  • taufiq
  • Posts: 7

Post 3+ Months Ago

HI, guys, thanks for taking your time to read this thread,
im newbie in as and getting stress now, so i hope anyone can help me
i have xml http://localhost/subcat/index.php/movie/genre ,and this is the code
Code: [ Select ]
<?xml version="1.0" encoding="UTF-8"?>
<data>
<genre id="1">
<id>1</id>
<root>0</root>
<name>Action</name>
<description>Action</description>
</genre>

<genre id="6">

<id>6</id>
<root>0</root>
<name>Thriller</name>
<description>Thriller</description>
</genre>

<genre id="7">
<id>7</id>

<root>0</root>
<name>Comedy</name>
<description>Comedy</description>
</genre>

<genre id="8">
<id>8</id>
<root>0</root>
<name>Romantic Comedy</name>

<description>Romantic Comedy</description>
</genre>

<genre id="10">
<id>10</id>
<root>0</root>
<name>Classics</name>
<description>Classics</description>
</genre>

<genre id="11">
<id>11</id>
<root>0</root>
<name>Cult</name>
<description>Cult</description>
</genre>

<genre id="12">

<id>12</id>
<root>0</root>
<name>Documentary</name>
<description>Documentary</description>
</genre>

<genre id="13">
<id>13</id>

<root>0</root>
<name>Indie / Foreign</name>
<description>Indie / Foreign</description>
</genre>

<genre id="15">
<id>15</id>
<root>0</root>
<name>Children</name>

<description>Children</description>
</genre>

<genre id="16">
<id>16</id>
<root>0</root>
<name>Musicals</name>
<description>Musicals</description>
</genre>

<genre id="18">
<id>18</id>
<root>0</root>
<name>TV Shows</name>
<description>TV Shows</description>
</genre>

<genre id="19">

<id>19</id>
<root>0</root>
<name>War</name>
<description>War</description>
</genre>

<genre id="23">
<id>23</id>

<root>0</root>
<name>Drama</name>
<description>Drama</description>
</genre>

<genre id="31">
<id>31</id>
<root>0</root>
<name>Music & Concert</name>

<description>Music & Concert</description>
</genre>

<genre id="43">
<id>43</id>
<root>13</root>
<name>special collection</name>
<description></description>
</genre>

<genre id="44">
<id>44</id>
<root>13</root>
<name>criterion collection</name>
<description></description>
</genre>

</data>
</xml>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <data>
  3. <genre id="1">
  4. <id>1</id>
  5. <root>0</root>
  6. <name>Action</name>
  7. <description>Action</description>
  8. </genre>
  9. <genre id="6">
  10. <id>6</id>
  11. <root>0</root>
  12. <name>Thriller</name>
  13. <description>Thriller</description>
  14. </genre>
  15. <genre id="7">
  16. <id>7</id>
  17. <root>0</root>
  18. <name>Comedy</name>
  19. <description>Comedy</description>
  20. </genre>
  21. <genre id="8">
  22. <id>8</id>
  23. <root>0</root>
  24. <name>Romantic Comedy</name>
  25. <description>Romantic Comedy</description>
  26. </genre>
  27. <genre id="10">
  28. <id>10</id>
  29. <root>0</root>
  30. <name>Classics</name>
  31. <description>Classics</description>
  32. </genre>
  33. <genre id="11">
  34. <id>11</id>
  35. <root>0</root>
  36. <name>Cult</name>
  37. <description>Cult</description>
  38. </genre>
  39. <genre id="12">
  40. <id>12</id>
  41. <root>0</root>
  42. <name>Documentary</name>
  43. <description>Documentary</description>
  44. </genre>
  45. <genre id="13">
  46. <id>13</id>
  47. <root>0</root>
  48. <name>Indie / Foreign</name>
  49. <description>Indie / Foreign</description>
  50. </genre>
  51. <genre id="15">
  52. <id>15</id>
  53. <root>0</root>
  54. <name>Children</name>
  55. <description>Children</description>
  56. </genre>
  57. <genre id="16">
  58. <id>16</id>
  59. <root>0</root>
  60. <name>Musicals</name>
  61. <description>Musicals</description>
  62. </genre>
  63. <genre id="18">
  64. <id>18</id>
  65. <root>0</root>
  66. <name>TV Shows</name>
  67. <description>TV Shows</description>
  68. </genre>
  69. <genre id="19">
  70. <id>19</id>
  71. <root>0</root>
  72. <name>War</name>
  73. <description>War</description>
  74. </genre>
  75. <genre id="23">
  76. <id>23</id>
  77. <root>0</root>
  78. <name>Drama</name>
  79. <description>Drama</description>
  80. </genre>
  81. <genre id="31">
  82. <id>31</id>
  83. <root>0</root>
  84. <name>Music & Concert</name>
  85. <description>Music & Concert</description>
  86. </genre>
  87. <genre id="43">
  88. <id>43</id>
  89. <root>13</root>
  90. <name>special collection</name>
  91. <description></description>
  92. </genre>
  93. <genre id="44">
  94. <id>44</id>
  95. <root>13</root>
  96. <name>criterion collection</name>
  97. <description></description>
  98. </genre>
  99. </data>
  100. </xml>


and now, i want to parsing the xml and get the id node from this xml
so here's the code:

Code: [ Select ]
/*global variabel declare*/
var label:TextField;
var duplicate_genre:MovieClip;
/*end declare*/
/*Opening connection with xml*/
myXML = new XML();
var id:Array;
var path_id:Array;
myXML.ignoreWhite = true;
myXML.load("http://localhost/subcat/index.php/movie/genre");
myXML.ref = this;
myXML.onLoad = function(succes) {
if (succes) {
var root = this.firstChild;
var nodes = root.childNodes;
for (var i = 0; i<nodes.length; i++) {
subnodes = nodes[i].childNodes;
duplicate_genre= _root.genre.createEmptyMovieClip(["container"+i], _root.genre.getNextHighestDepth());/*make container for dynamic txt genre*/
this["label"+i]=duplicate_genre.createTextField(["labelor"+i], 1, -422, (i*28.5)+(-200), 143.8, 22.6);/*declare position text for genre*/
/*conditional if text <20*/
if (i<20) {
this["label"+i].text = subnodes[2].firstChild.toString();/*write genre xml to dynamic text*/
path_id=_root.genre["id"+i]= this["container"+i]=subnodes[0].firstChild.toString();/*declare id genre xml*/
trace(duplicate_genre+path_id);
/*opening otherXML */
otherXML = new XML()
otherXML.ignoreWhite = true
duplicate_genre.onRelease = function() {
var string="http://localhost/subcat/index.php/movie/lists/1/"+_root.genre.path_id;/*declare url for movie list*/
trace(string);
otherXML.load(string);/*function for load url movie*/
otherXML.onLoad = function(succes) {
if (succes) {
var totalpage = this.childNodes[1].firstChild.toString();
totalpage_txt.text = "("+totalpage+" Movies)";/*function for display total page*/
var root = this.firstChild;
nodes = root.childNodes;
for (var i = 0; i<nodes.length; i++) {
subnodes = nodes[i].childNodes;
_root.genre["cover_title"+i].text = subnodes[1].firstChild.toString();/*function for display movie name*/
_root.genre["genre_name"].text = subnodes[3].firstChild.toString();/*function for display genre name*/
}
} else {
trace("Error loading otherXML");
}
};/*end other xml load function*/
};/*end conditional for on release*/
} else {
trace("erorr loading xml document");
}/*end if text < 20*/
}/*end for Myxml*/
} else {
trace("Error loading XML document");
}
};
/*end connection for myXML*/
  1. /*global variabel declare*/
  2. var label:TextField;
  3. var duplicate_genre:MovieClip;
  4. /*end declare*/
  5. /*Opening connection with xml*/
  6. myXML = new XML();
  7. var id:Array;
  8. var path_id:Array;
  9. myXML.ignoreWhite = true;
  10. myXML.load("http://localhost/subcat/index.php/movie/genre");
  11. myXML.ref = this;
  12. myXML.onLoad = function(succes) {
  13. if (succes) {
  14. var root = this.firstChild;
  15. var nodes = root.childNodes;
  16. for (var i = 0; i<nodes.length; i++) {
  17. subnodes = nodes[i].childNodes;
  18. duplicate_genre= _root.genre.createEmptyMovieClip(["container"+i], _root.genre.getNextHighestDepth());/*make container for dynamic txt genre*/
  19. this["label"+i]=duplicate_genre.createTextField(["labelor"+i], 1, -422, (i*28.5)+(-200), 143.8, 22.6);/*declare position text for genre*/
  20. /*conditional if text <20*/
  21. if (i<20) {
  22. this["label"+i].text = subnodes[2].firstChild.toString();/*write genre xml to dynamic text*/
  23. path_id=_root.genre["id"+i]= this["container"+i]=subnodes[0].firstChild.toString();/*declare id genre xml*/
  24. trace(duplicate_genre+path_id);
  25. /*opening otherXML */
  26. otherXML = new XML()
  27. otherXML.ignoreWhite = true
  28. duplicate_genre.onRelease = function() {
  29. var string="http://localhost/subcat/index.php/movie/lists/1/"+_root.genre.path_id;/*declare url for movie list*/
  30. trace(string);
  31. otherXML.load(string);/*function for load url movie*/
  32. otherXML.onLoad = function(succes) {
  33. if (succes) {
  34. var totalpage = this.childNodes[1].firstChild.toString();
  35. totalpage_txt.text = "("+totalpage+" Movies)";/*function for display total page*/
  36. var root = this.firstChild;
  37. nodes = root.childNodes;
  38. for (var i = 0; i<nodes.length; i++) {
  39. subnodes = nodes[i].childNodes;
  40. _root.genre["cover_title"+i].text = subnodes[1].firstChild.toString();/*function for display movie name*/
  41. _root.genre["genre_name"].text = subnodes[3].firstChild.toString();/*function for display genre name*/
  42. }
  43. } else {
  44. trace("Error loading otherXML");
  45. }
  46. };/*end other xml load function*/
  47. };/*end conditional for on release*/
  48. } else {
  49. trace("erorr loading xml document");
  50. }/*end if text < 20*/
  51. }/*end for Myxml*/
  52. } else {
  53. trace("Error loading XML document");
  54. }
  55. };
  56. /*end connection for myXML*/


the trouble begins here, when i want to take id node at xml and parsing it into http://localhost/subcat/index.php/movie/lists/1/"+_root.genre.path_id,
i'm always get id from the last xml which is "44", and can't be suitable with te container which i clicked,
can u see the problems??
sorry my poor english
anyone have advice???
otherwise i need to take idnode from movie/genre when i clicked, and then placing to movie/lists/i; which i is id from movie/genre
thanks...
please help me....
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

I'm not sure exactly what your asking for but there's an extremely good xml/as tutorial at Kirupa (AS3 Version) and (AS2 Version). You might want to read through that and see if it answers your questions. Sorry I couldn't be more help.
  • taufiq
  • Newbie
  • Newbie
  • taufiq
  • Posts: 7

Post 3+ Months Ago

hi graphicxx boy, thanks fot your rep.
i'll try to tell you more detail,

first, i load xml and parsing it with some element, textfield for example,
and as you can see in my xml(http://localhost/subcat/index.php/movie/genre) i have <id>node, and i want, when we clicked from one of movie clip, it will be parsing <id>node into new url which is
"http://localhost/subcat/index.php/movie/lists/"+id, which variable id is <id>node from http://localhost/subcat/index.php/movie/genre,before

i made code for this logic like that,
Code: [ Select ]
duplicate_genre.onRelease = function() {
var string="http://localhost/subcat/index.php/movie/list//"+_root.genre.path_id;/*declare url for movie list*/
trace(string);
  1. duplicate_genre.onRelease = function() {
  2. var string="http://localhost/subcat/index.php/movie/list//"+_root.genre.path_id;/*declare url for movie list*/
  3. trace(string);


but, this code only traces for the last id(44), and can be suitable with id for movie what we clicked,

ca u see the problems??
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

ahh ok I see what your asking. The problem is that your using a loop with a variable inside of it. Each iteration (loop) the variable will be overwritten with the most recent value. Therefore when you try to get the value of the variable after the loop ran you get the last value accessed.

the way around this is to store the value as a separate variable each time through the loop. Probably the easiest solution is to attach the value to your button...
Code: [ Select ]
duplicate_genre.targ = path_id; // you declare the path_id previously, now your storing it in the clip.
duplicate_genre.onRelease = function() {
trace(this.targ); // this being the clip and targ is the name we gave it
}
  1. duplicate_genre.targ = path_id; // you declare the path_id previously, now your storing it in the clip.
  2. duplicate_genre.onRelease = function() {
  3. trace(this.targ); // this being the clip and targ is the name we gave it
  4. }
  • taufiq
  • Newbie
  • Newbie
  • taufiq
  • Posts: 7

Post 3+ Months Ago

thank you very much, finnaly u see the problems :_)

yup, thats what i mean,
it always looping, so we can store id into button,
but sorry, where we get var:targ??
that's movie clip
thanks
  • taufiq
  • Newbie
  • Newbie
  • taufiq
  • Posts: 7

Post 3+ Months Ago

what??? it fixed,
thanks graphixbox why i'm not thinked as a simple that,

so much thank you,,,
thank you :D
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

you welcome. Good luck.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.