This language bar is your friend. Select your favorite languages!

Idiom #103 Load XML file into struct

Read from file data.xml and write its content into object x.
Assume the XML data is suitable for the type of x.

using System.Xml.Linq;
XDocument x = XDocument.Load("data.xml");

import orange.serialization._;
import orange.serialization.archives._;
import std.file;
XmlArchive archive = new XmlArchive!(char);
archive.doc.parse(read("data.xml"));
Serializer ser = new Serializer(archive);
ser.deserialize(x);
import "encoding/xml"
buffer, err := ioutil.ReadFile("data.xml")
if err != nil {
	return err
}
err = xml.Unmarshal(buffer, &x)
if err != nil {
	return err
}
use XML::LibXML qw();
my $x = XML::LibXML->load_xml(
location => 'data.xml');
import lxml.etree
x = lxml.etree.parse('data.xml')

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms