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

Idiom #103 Load XML file into struct

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

import "encoding/xml"
import "os"
buffer, err := os.ReadFile("data.xml")
if err != nil {
	return err
err = xml.Unmarshal(buffer, &x)
if err != nil {
	return err
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);
Serializer ser = new Serializer(archive);
def x = new XmlSlurper().parse(new File('data.xml'))
(ql:quickload :plump)
(let ((x (plump:parse #p"data.xml")))
use XML::LibXML qw();
my $x = XML::LibXML->load_xml(
location => 'data.xml');
import lxml.etree
x = lxml.etree.parse('data.xml')
import scala.xml.XML
val xml = XML.loadFile("data.xml")

New implementation...
< >