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 187143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:46:17+00:00 2026-05-11T15:46:17+00:00

One mistake I see people making over and over again is trying to parse

  • 0

One mistake I see people making over and over again is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard:

People want to treat a file as a sequence of lines, but this is valid:

<tag attr='5' /> 

People want to treat < or <tag as the start of a tag, but stuff like this exists in the wild:

<img src='imgtag.gif' alt='<img>' /> 

People often want to match starting tags to ending tags, but XML and HTML allow tags to contain themselves (which traditional regexes cannot handle at all):

<span id='outer'><span id='inner'>foo</span></span>  

People often want to match against the content of a document (such as the famous ‘find all phone numbers on a given page’ problem), but the data may be marked up (even if it appears to be normal when viewed):

<span class='phonenum'>(<span class='area code'>703</span>) <span class='prefix'>348</span>-<span class='linenum'>3020</span></span> 

Comments may contain poorly formatted or incomplete tags:

<a href='foo'>foo</a> <!-- FIXME:     <a href=' --> <a href='bar'>bar</a> 

What other gotchas are you aware of?

  • 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. 2026-05-11T15:46:18+00:00Added an answer on May 11, 2026 at 3:46 pm

    Here’s some fun valid XML for you:

    <!DOCTYPE x [ <!ENTITY y 'a]>b'> ]> <x>     <a b='&y;>' />     <![CDATA[[a>b <a>b <a]]>     <?x <a> <!-- <b> ?> c --> d </x> 

    And this little bundle of joy is valid HTML:

    <!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd' [     <!ENTITY % e 'href='hello''>     <!ENTITY e '<a %e;>'> ]>     <title>x</TITLE> </head>     <p id  =  a:b center>     <span / hello </span>     &amp<br left>     <!---- >t<!---> < -->     &e link </a> </body> 

    Not to mention all the browser-specific parsing for invalid constructs.

    Good luck pitting regex against that!

    EDIT (Jörg W Mittag): Here is another nice piece of well-formed, valid HTML 4.01:

    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'   'http://www.w3.org/TR/html4/strict.dtd'>  <HTML/   <HEAD/     <TITLE/>/     <P/> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's one for java and one for c# and here's… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer eval and exec are handy quick-and-dirty way to get some… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer Since you're floating both #inner-1 and #inner-2, you'll need a… May 12, 2026 at 1:06 am

Related Questions

Should I use old synchronized Vector collection, ArrayList with synchronized access or Collections.synchronizedList or
I'm fascinated by the CAPTCHA system used on SO... I would like to know
(Note: these two questions are similar, but more specific to ASP.Net) Consider a typical
Having at least one virtual method in a C++ class (or any of its

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.