[Templates] Using XML::Smart with template toolkit
Robert Clarke
robert.clarke@gmgrd.co.uk
Fri, 30 Jun 2006 09:15:35 +0100
=20
Thanks for your reply Mark,
I have used XML::Simple, though I have found it frustrating when dealing =
with more complex XML. I was investigating XML::Smart as a potential =
replacement, however it's apparent non-compatibility with TT is a bit of =
a show stopper.
Thanks
Rob
-----Original Message-----
From: Thomas, Mark - BLS CTR [mailto:Thomas.Mark@bls.gov]
Sent: 29 June 2006 17:39
To: Robert Clarke; templates@template-toolkit.org
Subject: [SPAM] - RE: [Templates] Using XML::Smart with template toolkit
- Email found in subject
> 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
--------------------------------------------------------
GMG Regional Digital is part of the Guardian Media Group plc.=20
=20
=20
=20
=20
CONFIDENTIALITY NOTICE. The information contained in this e-mail is =
intended only for templates@template-toolkit.org. It may contain =
privileged and confidential information that is exempt from disclosure =
by law and if you are not an intended recipient, you must not copy, =
distribute or take any action in reliance on it. If you have received =
this e-mail in error, you may notify us by telephone on 44 (0)161 832 =
7200. E-mail transmission cannot be guaranteed to be secure or =
error-free. The sender (robert.clarke@gmgrd.co.uk) therefore does not =
accept liability for any errors or omissions in the contents of this =
message, which arise as a result of e-mail transmission. If verification =
is required please request a hard-copy version. =20
=20
=20
=20
=20
=20
=20