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

  • SEARCH
  • Home
  • 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 6562997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:46:35+00:00 2026-05-25T13:46:35+00:00

Using perl’s XML::SAX module I’m parsing (x)html templates, and as a result am simply

  • 0

Using perl’s XML::SAX module I’m parsing (x)html templates, and as a result am simply echoing a lot of the input to output. I have a SAX event handler that extends XML::SAX::Base and implements the usual methods – start_element, end_element and so on.

Now my question concerns elements that do not take a closing tag – e.g <img />, <link />, and <input />. The parser will call start_element($element_name, %attribute_hash) and end_element for these tags, but how do I know that the element is self-contained?

In other words, I want to write out <img src="blah" /> as the same, not as <img ...></img>
which I belive is invalid.

Short of maintaining a list of these elements, what can I do? Is there a way in SAX of directly echoing an element as opposed to reconstructing it from what’s passed to the event handlers?

  • 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-25T13:46:36+00:00Added an answer on May 25, 2026 at 1:46 pm

    First, building off Quentin’s comment, you’re using an XML parser to handle HTML. There’s nothing particularly wrong with that as long as the HTML is relatively clean. However, if you need to be in compliance with HTML (as opposed to XHTML), then perhaps an XML parser is the wrong tool.

    If you want to hack around it, then here’s what you could do. Implement a characters() callback, which will set a flag if there are any non-whitespace characters present. The start_element() callback will reset this flag. The end_element() callback will consider the tag empty if the flag was not set and write the syntax accordingly.

    Note that this will also catch tags like <td></td>, transforming them to <td />.

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

Sidebar

Related Questions

I'm using Perl's XML::Twig module to transform XML into (X)HTML. I need to output
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am using XML::Twig to parse my input xml using Perl. I need to
I am using Perl for a script that takes in input as two short
I am using Perl to convert some XML to JSON. If the XML attribute
I'm using Perl's DBI module. I prepare a statement using placeholders, then execute the
Using Perl's XML::LibXSLT necessitates that I use XSLT 1.0, which means that I am
We have been using Perl's Net:Twitter CPAN module (version 3.12) and basic authentication (not
I'm using Perl's XML::Simple to parse deeply nested XML and would like to extract
I'm using Perl's Archive::Tar module. Problem with it is it pulls everything on to

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.