Groups | Blog | Home
all groups > flash (alternate) > january 2005 >

flash (alternate) : help newbie with reading XML problem



hsin
1/28/2005 11:45:04 AM
I try to read the value from XML file,
it read, but come out all wrong, I don't understand why, here is the code,
can someone help me out?
thanks ahead!
Willy

AS code
===========================
my_XML = new XML();
my_XML.onLoad = convertXML;
my_display = "Loading data ... ";
my_XML.load("data.xml");
var fileList = new Array();
var thumList = new Array();
var nViewList = new Array();
var cViewList = new Array();
var titleList = new Array();
var detailList = new Array();
var editionList = new Array();
var madeList = new Array();
var dateList = new Array();
function convertXML() {
if (this.loaded) {
my_display = "Data loaded.";
}
var mainTag = new XML();
var imageTag = new XML();
var no_i = 0;
var mainTag = this.firstChild.nextSibling;
if (mainTag.nodeName.toLowerCase() == "files") {
fileList = mainTag.childNodes;
my_display = "";
for (i=0; i<=mainTag.childNodes.length; i++) {
my_display = "---"+mainTag.childNodes.length;
if (fileList[i].nodeName.toLowerCase() == "image") {
//we get the child node array beneath the articles, aka the meat and
potatoes we are after
imageList = fileList[i].childNodes;
//and loop through that looking for the data we need
for (j=1; j<=imageList.length; j++) {
imageTag = imageList[j];
myTitle="<br>"+imageList.length;
imageType = imageTag.nodeName.toLowerCase();
if (imageType == "filename") {
fileList[no_i] = imageTag.firstChild.nodeValue;
no_i++;
}
if (imageType == "thumbnail") {
thumList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "normalview") {
nViewList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "closeview") {
cViewList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "detail") {
detailList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "title") {
titleList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "edition") {
editionList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "made") {
madeList[no_i-1] = imageTag.firstChild.nodeValue;
}
if (imageType == "date") {
dateList[no_i-1] = imageTag.firstChild.nodeValue;
}
}
// end for j
}
// end if image
}
// end for i
}
// end if files
for (i=0; i<=fileList.length; i++) {
//i_list += "<br>i="+i+" "+"<br>i="+fileList[i]+"<br>i="+i+"
"+thumList[i]+"<br>i="+i+" "+nViewList[i]+"<br>i="+i+"
"+cViewList[i]+"<br>i="+i+" "+detailList[i]+"<br>i="+i+"
"+titleList[i]+"<br>i="+i+" "+madeList[i]+"<br>i="+i+"
"+dateList[i]+"<br><br>==============<br><br>";
i_list +=
"i="+i+"<br>"+"fileList="+fileList[i]+"<br>"+"thumList="+thumList[i]+"<br>"+
"nViewList="+nViewList[i]+"<br>"+"cViewList="+cViewList[i]+"<br>"+"detailLis
t="+detailList[i]+"<br>"+"titleList="+titleList[i]+"<br>"+"madeList="+madeLi
st[i]+"<br>"+"dateList="+dateList[i]+"<br>"+"<br><br>==============<br><br>"
;
}
}
===========================

XML file
============================
<?xml version="1.0" encoding="utf-8"?>
<files>
<image id="1">
<filename>01</filename>
<thumbnail>images/1_0.jpg</thumbnail>
<normalview>images/1_1.jpg</normalview>
<closeview>images/1_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail xml:space="preserve">The marbles remind me of my playful
youth,
but they also are symbolic of my maturation; most scattered marbles
contain
a Chinese brush painted lotus or venerable-Buddhist symbols that
represent my goal of gradual enlightenment.</detail>
<edition>40" * 59", 8 editions</edition>
<made>ink jet print on acetate or mount on plexi glass</made>
<date>2003/2004</date>
</image>
<image id="2">
<filename>02</filename>
<thumbnail>images/2_0.jpg</thumbnail>
<normalview>images/2_1.jpg</normalview>
<closeview>images/2_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail>The marbles remind me of my playful youth, but they also are
symbolic of my maturation; most scattered marbles contain a Chinese brush
painted lotus or venerable-Buddhist symbols that represent my goal of
gradual enlightenment.</detail>
<edition>40" * 59", 8 editions</edition>
<made>ink jet print on acetate or mount on plexi glass</made>
<date>2003/2004</date>
</image>
<image id="3">
<filename>03</filename>
<thumbnail>images/3_0.jpg</thumbnail>
<normalview>images/3_1.jpg</normalview>
<closeview>images/3_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail>The marbles remind me of my playful youth, but they also are
symbolic of my maturation; most scattered marbles contain a Chinese brush
painted lotus or venerable-Buddhist symbols that represent my goal of
gradual enlightenment.</detail>
<edition>40" * 59", 8 editions</edition>
<made>ink jet print on acetate or mount on plexi glass</made>
<date>2003/2004</date>
</image>
<image id="4">
<filename>04</filename>
<thumbnail>images/4_0.jpg</thumbnail>
<normalview>images/4_1.jpg</normalview>
<closeview>images/4_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail>The marbles remind me of my playful youth, but they also are
symbolic of my maturation; most scattered marbles contain a Chinese brush
painted lotus or venerable-Buddhist symbols that represent my goal of
gradual enlightenment.</detail>
<edition>40" * 59", 8 editions</edition>
<made>ink jet print on acetate or mount on plexi glass</made>
<date>2003/2004</date>
</image>
<image id="5">
<filename>05</filename>
<thumbnail>images/5_0.jpg</thumbnail>
<normalview>images/5_1.jpg</normalview>
<closeview>images/5_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail>The marbles remind me of my playful youth, but they also are
symbolic of my maturation; most scattered marbles contain a Chinese brush
painted lotus or venerable-Buddhist symbols that represent my goal of
gradual enlightenment.</detail>
<edition>40" * 59", 8 editions</edition>
<made>ink jet print on acetate or mount on plexi glass</made>
<date>2003/2004</date>
</image>
<image id="6">
<filename>06</filename>
<thumbnail>images/6_0.jpg</thumbnail>
<normalview>images/6_1.jpg</normalview>
<closeview>images/6_2.jpg</closeview>
<title>Marble Series, No. three</title>
<detail>The marbles remind me of my playful youth, but they also are
symbolic of my maturation; most scattered marbles contain a Chinese brush
painted lotus or venerable-Buddhist symbols that represent my goal of
gradual enlightenment.</detail>
hsin
1/28/2005 6:51:30 PM
thanks for the help, I think i didn't make it clear what is wrong with my
code,
i mean after my code read the XML file, all the elements are mess up.



[quoted text, click to view]
Samuria
1/28/2005 10:35:27 PM
On Fri, 28 Jan 2005 11:45:04 -0500, "hsin" <hsinhsin@comcast.net>
[quoted text, click to view]

The easy way to do it is use a textarea and then use

content.multiline= true;
content.wordWrap = true;
content.html = true;

story = new XML();
story.ignoreWhite = true;
story.html = true;
story.wordWrap = true;
story.load("help.xml");
story.onLoad = function () {
content.htmlText = story;
}

you can see it working @
http://www.janwright.co.uk/war

The secret is to use a stye sheet to do the formating ie
BODY {SCROLLBAR-FACE-COLOR: #8080FF; SCROLLBAR-HIGHLIGHT-COLOR:
#89A3B4; SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR:
#000000; SCROLLBAR-ARROW-COLOR: #FFFF80; SCROLLBAR-TRACK-COLOR:
#004080; SCROLLBAR-DARKSHADOW-COLOR: #000000; border: medium groove
#C0C0C0; cursor: default; outline: #f9bd64 ridge; accelerator: true;
border-style: groove groove ridge ridge; text-align: justify;
border-color: transparent; border-bottom-color: silver;
border-left-color: silver; border-right-color: gray; border-top-color:
gray; border-bottom-style: groove; border-left-style: groove;
border-right-style: ridge; border-top-style: ridge; border-top:
groove; border-right: ridge; border-bottom: ridge; border-left: ridge}
body, td, left, p, div {
font-family: verdana;
font-size: 9pt;
}
headline {font-family: Arial,Helvetica,sans-serif; font-size: 16px;
font-weight: bold; display: list-item; color: #0000CC}
subheadline {font-family: Arial,Helvetica,sans-serif; font-size: 12px;
font-weight: bold; display: list-item}
mainBody {font-family: Arial,Helvetica,sans-serif; font-size: 10px;
display: Block}
biline {
font-family: Arial,Helvetica,sans-serif; font-size: 8px; font-style:
italic; display:inline; }
A {
font-family: Arial,Helvetica,sans-serif; color: cccccc; font-size:
12px; display: table; text-decoration: underline}


[quoted text, click to view]
AddThis Social Bookmark Button
View Other Months
January 2005
February 2005