Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML importing problems, missing nodes

Status
Not open for further replies.

Fion

Vendor
Sep 25, 2003
50
US
Hi all,
This time I have a question I am hoping someone can help me with.
I have an XML document that I am importing for settings, but for some reason, it will only import 3 nodes... I have about 7 in there now, and I had planned quite a few more, but it only sees the first three. I don't understand it... does anyone know why this might happen?
Below is the text of my XML document, and when I import the XML, and immeadiatly trace it, it only shows the first 3 songs...
Any help you could give me would be greatly appreaciated.
Thanks!

Fion


<lyrics>
<song Type="Coro" TitleP="Abalou Capoeira, Abalou" TitleE="It shook, capoeira shook" Por= "Songs/AbalouPor.txt" Eng = "Songs/AbalouEng.txt"> </song>
<song Type="Coro" TitleP="Adeus (Boa Viagem)" TitleE="Goodbye (Good trip)" Por= "Songs/AdeusPor.txt" Eng = "Songs/AdeusEng.txt"> </song>
<song Type="Coro" TitleP="Ai ai ai ai" TitleE="Ai ai ai ai" Por="Songs/AiaiaiaiPor.txt" Eng ="Songs/AiaiaiaiEng.txt"> </song>
<song Type="Coro" TitleP="Ai ai, aidê" TitleE="Ai ai, aidê" Por="Songs/AiaiaidePor.txt" Eng ="Songs/AiaiaidePor.txt"> </song>
<song Type="Coro" TitleP="Abalou Capoeira, Abalou" TitleE="It shook, capoeira shook" Por= "Songs/AbalouPor.txt" Eng = "Songs/AbalouEng.txt"> </song>
<song Type="Coro" TitleP="Adeus (Boa Viagem)" TitleE="Goodbye (Good trip)" Por= "Songs/AdeusPor.txt" Eng = "Songs/AdeusEng.txt"> </song>
<song Type="Coro" TitleP="Ai ai ai ai" TitleE="Ai ai ai ai" Por="Songs/AiaiaiaiPor.txt" Eng ="Songs/AiaiaiaiEng.txt"> </song>
<song Type="Coro" TitleP="Ai ai, aidê" TitleE="Ai ai, aidê" Por="Songs/AiaiaidePor.txt" Eng ="Songs/AiaiaidePor.txt"> </song>
</lyrics>

 
It would be easier to help you with the problems with your Flash movie if you could post your actionscript. :)

There is nothing wrong with your XML.

Wow JT that almost looked like you knew what you were doing!
 
Ok, sorry about the time lapse here. Here is the XML loading part of the actionscript. I have the same basic code in a few other movies, and I haven't ever had a problem...

////////////////////////////////
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
pages[0] = "CoverPage"
for (i=0; i<total; i++) {

j = i+1
pages[j] = "page"+i;
}}
}

// XML
var xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml/lyrics.xml");

 
Was able to get all 8 childNodes by adding an ID field to your XML. (increment for each child node)

Code:
<song [highlight]id="1"[/highlight] Type="Coro" TitleP="Abalou Capoeira, Abalou" TitleE="It shook, capoeira shook" Por= "Songs/AbalouPor.txt"  Eng = "Songs/AbalouEng.txt"> </song>

To trace the problem to the XML I commented out your onLoad function and simply put added trace(xmlData) in the onLoad function. That showed that only three records were even coming in on the xml.load. I did notice that there was an extra space between song and Type, but otherwise I'm not sure what exactly was causing the problem. Maybe someone else can shed light on the reason, but adding a unique id (always a good idea anyway) to each record seems to fix it.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Excellent! Thanks alot, I never would have thought of that! So you arn't actually calling th ID field? Just having it exist is enough?

nifty...

Fion
 
I tested it with your code and just that addition to the XML datasource. So just existing seems to turn the trick. :)

Wow JT that almost looked like you knew what you were doing!
 
Doh, this isn't working for me... I used the exact code above (even copied it from above, in case I had typed something wrong...) and added the id field to my xml, but It still sees only 3 nodes... I could understand if it saw nothing, but only 3... that bugs me I even deleted nodes 2 and 3 and left the rest, and it only then sees node one. It's so odd...
 
There are errors in your script. Sorry I forgot I fixed it when I tested.

Code:
function loadXML(loaded) {
	if(loaded){
		xmlNode = [highlight]xmlData[/highlight].firstChild;
		total = xmlNode.childNodes.length;
		[highlight]var pages:Array = Array();[/highlight]
		pages[0] = "Coverpage";
		for(i=0;i<=total;i++){
			pages[i+1] = " page " +i;
		}
		trace(pages);// returns "Coverpage, page 0, page 1, page 2, page 3, page 4, page 5, page 6, page 7, page 8"
	}
}
// XML
var xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml/lyrics.xml");

At the top you have to use xmlData because that is the name of the XML object you loaded the data into. Also you need to define pages as an array.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Oh ya, sorry I forgot about that. There is ALOT more actionscript on that page, including a variable declaration area.. That wasn't the problem. I did finally (last night), fix it though. The problem was that I had portuguese characters in the text file, but I did not have it saved as a UTF-8 format... When flash tried to import those files, it died when it hit the extra characters.
I do want to thank you for your help though!
Thanks!

Fion
 
LOL you neglected to mention that :)

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top