Ultrashock Forums > Flash > ActionScript > XML
XML - White space ?

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
XML - White space ?
Old 4 Weeks Ago

XML - White space ?

Hi all

I have a simple xml file that I'm using to load images

Code:
        <travel&lifestyle>
		<image>images/travel/1marakesh</image>
		<image>images/travel/2marakesh</image>
		<image>images/travel/3marakesh</image>
		<image>images/travel/4marakesh</image>
		<image>images/travel/5new york</image>
	</travel&lifestyle>
I'm using the name of the base tag as the name of the nav to load the images. So from the xml above the nav button would be

"travel & lifestyle"

I know flash removes the whitespace but what if I want whitespace there.

If I try

Code:
<travel & lifestyle>
The xml won't load and I get an error loading the xml file into Firefox

"XML Parsing Error: not well-formed"

How can I format the xml to keep the space

Thanks in advance for any help
postbit arrow 3 comments | 198 views postbit arrow Reply: with Quote   
Registered User
ttmt is offline
seperator
Posts: 6
2009-04-09
ttmt lives in United Kingdom
seperator

Ultrashock Member Comments:
tiran tiran is offline tiran lives in United States 4 Weeks Ago #2 Old  
Last edited by tiran : 4 Weeks Ago at 08:45.
You can't use an ampersand in a node name I don't think. And there can definitely be no spaces in the node name. Consider this XML structure:

ActionScript Code:
  1. <imageSet>
  2. <name><![CDATA[Travel & LifeStyle]]></name>
  3. <images>
  4.         <image>http://www.ultrashock.com/forums/images/travel/1marakesh</image>
  5.         <image>http://www.ultrashock.com/forums/images/travel/2marakesh</image>
  6.         <image>http://www.ultrashock.com/forums/images/travel/3marakesh</image>
  7.         <image>http://www.ultrashock.com/forums/images/travel/4marakesh</image>
  8.         <image>http://www.ultrashock.com/forums/images/travel/5newyork</image>
  9. </images>
  10. </imageSet>

I used the CDATA tag because of the Ampersand in the title - Flash doesn't care a ton about that in this context, but its a good practice in nodes that might contain special chars or HTML.

This will allow you to query the XML based on the "name" nodes value in flash.

What version of AS are you using and I can elaborate.
Reply With Quote  
ttmt ttmt is offline ttmt lives in United Kingdom 4 Weeks Ago #3 Old  
tiran

Thanks for your replay - I'm using AS3.

I've solved the problem by putting the name as an attribute of the node
Reply With Quote  
tiran tiran is offline tiran lives in United States 4 Weeks Ago #4 Old  
Cool, I should also mention that putting something like "Travel & Lifestyle" in an attribute is technically still bad form because of the "&". There aren't supposed to be special characters in attributes - these days they can be escaped and Flash isn't as strict as say an RSS feed, so you will be ok for the most part.

Keep in mind this example though. Look what happens to the '&' in the attribute as opposed to the '&' in the CDATA

ActionScript Code:
  1. var xml:XML =new XML("<root><item name=\"Travel & Lifestyle\" ><name><![CDATA[Travel & LifeStyle]]></name></item><item name=\"New\" /></root>");
  2. trace(xml);

The trace looks like this:

Code:
<root>
  <item name="Travel &amp; Lifestyle">
    <name><![CDATA[Travel & LifeStyle]]></name>
  </item>
  <item name="New"/>
</root>
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: