Notice: register_sidebar was called incorrectly. No id was set in the arguments array for the "Sidebar" sidebar. Defaulting to "sidebar-1". Manually set the id to "sidebar-1" to silence this notice and keep existing sidebar content. Please see Debugging in WordPress for more information. (This message was added in version 4.2.0.) in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 4147

Notice: The called constructor method for WP_Widget in mts_Widget_Tabs is deprecated since version 4.3.0! Use
__construct()
instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 3902

Notice: The called constructor method for WP_Widget in mts_ad_widget is deprecated since version 4.3.0! Use
__construct()
instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 3902

Notice: The called constructor method for WP_Widget in mts_ad_300_widget is deprecated since version 4.3.0! Use
__construct()
instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 3902

Notice: The called constructor method for WP_Widget in swt_tweet_widget is deprecated since version 4.3.0! Use
__construct()
instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 3902

Notice: The called constructor method for WP_Widget in Facebook_Like_Widget is deprecated since version 4.3.0! Use
__construct()
instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 3902
E4X XML Namespaces

E4X XML Namespaces


Notice: Undefined index: mts_posttop_adcode in /home1/jccrosby/public_html/admin.crsby.com/wp-content/themes/playbook/single.php on line 19

For XML that looks like the following response from Yahoo’s weather service:
[xml]
< ?xml version=’1.0′ encoding=’UTF-8′?>
http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*
http://weather.yahoo.com/forecast/94089_f.html Yahoo! Weather for Sunnyvale, CA
en-us
Tue, 06 Nov 2007 6:56 pm PST
60

142
18

http://weather.yahoo.com/ http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif
37.39
-122.03

http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/94089_f.html Tue, 06 Nov 2007 6:56 pm PST

< ![CDATA[

Current Conditions:
Fair, 55 F

Forecast:
Tue – Mostly Clear. High: 67 Low: 49
Wed – Partly Cloudy. High: 71 Low: 49

Full Forecast at Yahoo! Weather
(provided by The Weather Channel)
]]>

94089_2007_11_06_18_56_PST

[/xml]

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:

[as]
var yweatherNS:Namespace = new Namespace( http://xml.weather.yahoo.com/ns/rss/1.0 );
[/as]

Now we can access the node with the following code:

[as]
yahooWeaterXML.channel.yweatherNS::location

trace( yahooWeaterXML.channel.yweatherNS::location.@city ); // outputs ‘Sunnyvale’
trace( yahooWeaterXML.channel.yweatherNS::location.@region); // outputs ‘CA’
trace( yahooWeaterXML.channel.yweatherNS::location.@country ); // outputs ‘US’
[/as]

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:

[as]
var namespaces:Array = myXML.namespaceDeclarations();
[/as]

Now we have an array of namespace declarations that we can use to dynamically declare Namespace objects and access our complex node names:

[as]
var yweatherNS:Namespace
var geoNS:Namespace
var nsLen:uint = nameSpaces.length;
for(var i:uint = 0; i < nsLen; i++)
{
var newNamespace:Namespace = new Namespace( nameSpaces[i] );
if( String( nameSpaces[i].prefix ).toLowerCase() == “yweather” )
{
yweatherNS = newNamespace;
}
else
{
geoNS = newNamespace;
}
}
[/as]

So we can access the geo and yweather nodes without any problems now.


Notice: Undefined variable: defaults in /home1/jccrosby/public_html/admin.crsby.com/wp-content/themes/playbook/functions.php on line 340

Notice: Undefined index: mts_postend_adcode in /home1/jccrosby/public_html/admin.crsby.com/wp-content/themes/playbook/single.php on line 28

Notice: WP_Query was called with an argument that is deprecated since version 3.1.0! caller_get_posts is deprecated. Use ignore_sticky_posts instead. in /home1/jccrosby/public_html/admin.crsby.com/wp-includes/functions.php on line 4031
Comments
  1. Parag
  2. Sunil
  3. jccrosby

Leave a Reply

Your email address will not be published. Required fields are marked *