While creating a sample application for some class content the other day, I ran into an XML/E4X situation that I'd never encountered before. It is pretty basic - deleting a node from XML. How does one do it? With the delete keyword of course!
download:Delete Node Example (4.78KB) added: 04/09/2009 clicks: 72 description: Code source (.FLA) for delete XML node using E4X in ActionScript 3 sample
<ahref="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/* http://weather.yahoo.com/forecast/94089_f.html">Full Forecast at Yahoo! Weather</a>
(provided by The Weather Channel)
]]>
94089_2007_11_06_18_56_PST
When you need to access the nodes with complex node names such as yweather:location think XML namespaces.
In the above example, look for the xmlns declaration in the rss node
- xmlns:yweather='http://xml.weather.yahoo.com/ns/rss/1.0'.
Creating a Namespace object using the declaration will allow us to access the nodes with complex names.
Creating a Namespace object is a pretty simple process:
With the preceding example we need to know the namespace url ahead of time. E4X gives us the namespaceDeclarations() method that will return an array that contains the namespace declarations associated with the XML document
Using the namespaceDeclarations() method from the XML object:
TWO: If you are are expecting a response, use the sendAndLoad() method. You will need to create an XML object to catch the response from your server. The sendAndLoad() method takes 3 parameters:
url - where to send the XML
target - The XML object that receives the downloaded data (this can also be a LoadVars object depending on the data that is returned from the service)
method - GET or POST HTTP protocol. This parameter is optional.
Now what happens if you don't expect a response from the server? Do you use send()? Not if you don't want the page to redirect.
The send() method can GET or POST your XML data to a page, but your Flash piece page is expected to redirect. So, what do you do. Well, just use sendAndLoad() and create a dummy XML object for the 2nd parameter. You won't receive a response, but the XML will be sent to the server just the same.
I'm a senior developer at RealEyes Media, Adobe Certified Instructor and Adobe Certified Professional. Here you'll get my ideas and experience Flex, Flash, ColdFusion and related technologies as well as some generally off the wall stuff.