1

I am very new to XML so apologies if this is a simple question;

I have the following line of code in a PHP file which is used to create a resulting line of code in an XML file via a PHP form;

$Savings = $xml->createElement('Savings');

This creates the following line in my XML file;

<Savings>263.4</Savings>

How would I change this line in my XML file to look as follows;

<Savings Currency="EUR">263.4</Savings>

I have tried the following but I get no additional output;

 $Savings = $xml->createElementNS('EUR', 'Savings');
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
Sarah92
  • 87
  • 11

1 Answers1

1

Use setAttribute:

$Savings = $xml->createElement('Savings');
$Savings->setAttribute('Currency', 'EUR');
Steve
  • 20,703
  • 5
  • 41
  • 67