I’ve successfully loaded an xml file into a textarea component, but it creates A LOT of line-breaks which I can’t seem to get rid of. This is the first time I’ve ever done this, so I’m guessing I’m doing something stupid, and any help would be appreciated.
Here’s an example of the XML:
<?xml version=“1.0” encoding=“UTF-8”?>
<resources>
<resource name=‘Entertainment’>
<ent name = ‘Opera’>
<name>Opera</name>
<address>2345 Street</address>
<city>sf</city>
<phone>123-123-1234</phone>
<email>email@email.com</email>
</ent>
<ent name = 'Theatre'>
<name>Theatre</name>
<address>2222 Street</address>
<city>sf</city>
<phone>123-123-1234</phone>
<email>email@email.com</email>
</ent>
</resource>
</resources>
And here’s an example of the AS3 that loads and place the XML into the textarea(called resources_dt):
var printOut:String = new String;
function LoadXMLExample()
{
var loader:URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, handleComplete);
loader.load(new URLRequest("…/xml/liveUrban.xml"));
};
function handleComplete(event:Event)
{
try{
var resources:XML = new XML(event.target.data);
resources.ignoreWhitespace = true;
function readAddress(targ:XML)
{
if(targ.address){
printOut += targ.address+"<br />"+targ.city+"<br />"+targ.phone+"<br /><a href='mailto:"+targ.email+"'>"+targ.email+"</a><br >";
};
};
function walk(node:XML):void
{
for each (var element:XML in node.elements())
{
printOut += "<b>"+element.@name+"</b><br />";
readAddress(element);
walk(element);
}
}
walk(resources);
}
catch (e:TypeError)
{
trace("coundn't parse it");
trace(e.message);
}
resources_dt.htmlText = printOut;
}
LoadXMLExample();
I’ve thought of a way to cheat my way around this, but I’m still really frustrated by the fact that I was unable to get rid of those annoying line-breaks.
I apologize in advance if it turns out this was a stupid question.
T