Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:22:41+00:00 2026-05-22T21:22:41+00:00

When I create an XML document, I use Perl, but this question is language

  • 0

When I create an XML document, I use Perl, but this question is language agnostic. Most people seem to do this task with tools like XML::Writer or XML::LibXML. It looks like this:

my $writer = XML::Writer->new();
my $type = "fancy";
$writer->startTag("pants");
$writer->characters($type);
$writer->endTag("pants");

I kind of hate this. It feels like that first web page you create as a beginner web developer where you mix all the HTML, CSS, and PHP code together in the same file because you haven’t learned about MVC yet. And everyone agrees this is terrible and we should separate this all out and try to keep languages separate as much as possible. It improves readability if nothing else.

So why is it ok to put XML in our Perl code? My idea is to use Template::Toolkit just like we do with HTML. So it would look like this:

 <pants>
     [% type %]
 <pants>

Afterwards, I can slurp the result into XML::LibXML and validate the string.

But I don’t think anyone does it this way. Why not? Am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:22:42+00:00Added an answer on May 22, 2026 at 9:22 pm

    I’ve used Template::Toolkit for XML. I’ve also used the more programatic XML::Writer style approach.

    If you have a fixed XML structure that you’re simply filling in with data and you have Template::Toolkit already around, then using a TT template for your XML makes a lot of sense; using a template in this case probably makes it a lot easier to properly match the desired schema. But, of course, be careful with properly escaping and encoding everything for XML rather than HTML.

    If you’re programatically converting arbitrary structured data to XML then XML::Writer is probably a better choice: if you don’t have a fixed schema then there’s nothing to template.

    XML is often used as a portable data serialization format. The archetypal example is starting with some nested HoHoA data structure and converting that to XML through a general serialization interface. The serialization system just has a data structure to walk through so there is no structure to template.

    Also, people tend to use the first technique they learn even when there are better ways. I’d guess that most people come across XML for data serialization (rather than structure document storage) first so they keep using serialization techniques even when a template approach would be cleaner.

    All of this (even the first paragraph) applies to JSON (and even HTML) equally well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There seem to be many options to create an XML document in .NET. What's
I need to manipulate an existing XML document, and create a new one from
I have created a xslt document which formats an xml document, but I would
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I wrote the following Perl script (below) in order to create simple XML file.
I create the following XML file, by perl script (Showing down) , using XML::LibXML:
I'm using JavScript and jQuery to read an XML document and subsequently use the
I would like to create XML Schema for this chunk of xml, I would
I've encountered an issue whereby when I create an XML Document programmatically using the
I have to parse an XML document & create a HTML element for every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.