class Person
include XML::Mapping
attr_accessor :name, :surname, :age, :children
text_node :from, "@from"
text_node :name, "Name"
text_node :surname, "Surname"
def initialize(name, surname, ..)
# ...
end
end
x = Person.new(..)
x.save_to_xml.write($stdout,2) # nicely prints
x.save_to_file('data.xml')
class Test
{
public $f1;
private $f2;
public function __construct($f1, $f2)
{
$this->f1 = $f1;
$this->f2 = $f2;
}
}
$x = new Test('foo', 42);
$options = array(
XML_SERIALIZER_OPTION_INDENT => ' ',
XML_SERIALIZER_OPTION_RETURN_RESULT => true
);
$serializer = new XML_Serializer($options);
$result = "<?xml version=\"1.0\"?>\n" . $serializer->serialize($x);
file_put_contents('data.xml', $result);