Lasso Soft Inc. > Home

[ xml_element->setattribute ]

Method

The [xml_element->setattribute] method sets the value of the named attribute of an xml_element.

This method requires two string parameters. The first is the name of the attribute to set, the second is the value of the attribute. 

If the named attribute is not present in the element [xml_element->setattribute] will add it to the element.

  • Syntax
xml_element->setattribute( 'attribute_name', 'value' )
Examples
  • Beginner

Update the value of an attribute of an xml element.

Use the [xml_element->setattribute] method.

This example shows how to change the "day" attribute of the "vacation" xml_element.

Code

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

'Day is '+$vacationDays->getattribute('day')+'\n'

//change the value
$vacationDays->setattribute('day', '21')
'Day is '+$vacationDays->getattribute('day')

Result

Day is 23
Day is 21

Add an attribute to an xml_element

This example shows how to add an attribute called "month" with the value "March" to the "vacation" xml_element above.

Code

$vacationDays->settattribute('month', 'March')

$vacationDays

Result

<vacation day="21" weekday="Friday" month="March">
     <employee>Sean</employee>
</vacation>

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