[Templates] Using XML::Smart with template toolkit

Thomas, Mark - BLS CTR Thomas.Mark@bls.gov
Thu, 29 Jun 2006 12:39:20 -0400


> Assuming that I have some XML like this
>=20
> <person>
>   <name>mr jones</name>
>   <contact>
>     <telephone>01234 5678910</telephone>
>   </contact>
> </person>
>=20
> I can create an XML::Smart object using this XML and access=20
> the values in perl as follows:
>=20
> $telephoneno =3D $myxml->{person}->{contact}->{telephone};
>=20
> If I pass the XML::Smart object into a TT template I would=20
> expect this to display the telephone number
>=20
> [% myxml.person.contact.telephone %]

It would seem that TT is getting hung up on Object::Multitype, which is
used by XML::Smart. Have you checked out XML::Simple? It creates a
regular hash, so if you do:
  my $person =3D XMLin($xml);

Then you can have the (normal) perl hash:
  my $telephoneno =3D $person->{contact}->{telephone};

And you should be able use it in your template:
  [% person.contact.telephone %]

--=20
Mark Thomas=20