Warning: A non-numeric value encountered in /homepages/10/d677520614/htdocs/ryanragle.com/wp-content/themes/Divi/functions.php on line 5560

Sometimes when accessing XML with E4X you need to periodically check if an attibute is populated. If not, you may want to fill with a default attribute. This is usually done with the following syntax:

if (myXMLElement.@myAttribute == “”){     myXMLElement.@myAttribute = “myDefaultValue”;}

The problem is, this returns back false, even if empty. Here is one way to check to make sure the attribute contains some data:

if (myXMLElement.@myAttribute.toString() == “”) {     myXMLElement.@myAttribute = myDefaultValue”;}

By adding the .toString(), the comparison now gives back accurate results.