Lasso Soft Inc. > Home

[ xml_element->hasattribute ]

Method

The [xml_element->hasattribute] method is used to test for the existence of a particular attribute in an xml_element

The method has one required parameter, the name of the attribute to test for. Returns true it the attribute is present, false otherwise.

  • Syntax
if( xml_element->hasattribute( 'attribute_name' ) ) => {^  ^}
Examples
  • Beginner

To test for the existence of an attribute in an xml_element

This example uses the [xml_element->hasattribute] method to verifiy that the 'vacation' xml_element has the weekday element. if not it uses the day and month attributes to set it.

Code

var(vacationDays = xml('<vacation day="23" month="March">
     <employee>Sean</employee>
</vacation>') )

if( !$vacationDays->hasattribute('weekday') ) => {^ 
     local( 'weekday' = date($vacationDays->getattribute('month')+' '+$vacationDays->getattribute('day')+' '+date->year, -format="%B %d %Y") )
     $vacationDays->setattribute('weekday', #weekday->format("%A"))
^}

 'weekday is '+$vacationDays->getattribute('weekday')

Result

weekday is Wednesday

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft