PDA

View Full Version : why the XML loading into flash but not html??



boozy juice
January 15th, 2008, 09:12 AM
Im trying to build a Flash site and a basic HTML mirror site. Im wanting both to load from the same XML file (as a 'news' section probably).

Anyway, ive found some useful articles and tutorials so im trying to combine them, heres what i have so far:

the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="news.css"?>

<!DOCTYPE data[
<!ELEMENT title (comments, image)>
<!ATTLIST title name CDATA #REQUIRED>
<!ELEMENT comments (#PCDATA)>
<!ELEMENT image (#PCDATA)>
]>
<data>
<title name="News article 1">
<comments>Work wins another new account. But says goodbye to an old one.</comments>
<image>logo1.gif</image>
</title>
<title name="News article 2">
<comments>Another winning account at work. Our boss has announced he is 'jubilant with the whole team'.</comments>
<image>logo2.gif</image>
</title>
</data>

while the HTML - lifted from http://www.w3schools.com/xml/xml_to_html.asp - looks like this:


<html>
<head>
<script language="javascript" type="text/javascript" src="swfobject.js"></script>

</head>
<body>
<script type="text/javascript">
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load("news.xml");

var x=xmlDoc.getElementsByTagName("title");

document.write("<table border='1'>");
for (var i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("comments")[0].childNodes[0].nodeValue);
document.write("</td>");

document.write("<td>");
document.write(
x[i].getElementsByTagName("image")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
</script>

<br>
<br>
<br>

<span id="moving">Flash not working</span>
<script type="text/javascript" language="javascript">
var so = new SWFObject("load_XML.swf", "moving", "550", "400", "8", "#ffffff");
so.write("moving");
</script>

</body>
</html>


<br>
<br>
<br>

<span id="moving">Flash not working</span>
<script type="text/javascript" language="javascript">
var so = new SWFObject("load_XML.swf", "moving", "550", "400", "8", "#ffffff");
so.write("moving");
</script>

</body>
</html>[/HTML]

and im using the load xml tutorial from here: http://www.flash-db.com/Tutorials/loading/ like so -


myXML = new XML()
myXML.ignoreWhite = true
//Load XML file
myXML.load("news.xml")
//Make a reference to current timeline
myXML.ref = this
// Parse XML and fetch
myXML.onLoad = function(succes){
if(succes){
var root = this.firstChild
nodes = root.childNodes
for(var i=0; i<nodes.length; i++) {
this.ref["Title_txt"+i].text = nodes[i].attributes.name
subnodes = nodes[i].childNodes
this.ref["Comments_txt"+i].text = subnodes[0].firstChild.toString()
this.ref["holder_mc"+i].loadMovie(subnodes[1].firstChild.toString())
}
} else trace("Error loading XML document")
}
stop()

i can get the flash one to work ok, but the HTML one doesnt work - all the HTML code seems to be calling the right ('title') nodes from what i can make out.. so, can anyone please assist me as to why its not working here, please??

thanks

joran420
January 15th, 2008, 01:49 PM
look into the simplexml object...Ive found that to be awesome for php

[edit] nm your using JS and asp...dunno how to do that :P

boozy juice
January 15th, 2008, 02:53 PM
thanks joran ill look into the simplexml object.. and yeah, im not adverse to using some php if thats an route to go down ;)

and as for your mention of asp code - i cant see any anywhere in that code i presented earlier =/ - but then i dont program with it so wouldnt use it knowingly.

joran420
January 15th, 2008, 03:04 PM
i just assumed on the ASP...since you were doing it with JS...

I would look into simplexml if you can use php....I struggled with xml for a long time until i figured that one out (its a built in thing in php 5...maybe php4)

but it makes reading nodes easy...makes reading attributes easy makes manipulating nodes easy and makes writing XML easy :P