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

Related Questions

I'm probably making a stupid beginner mistake here but SQL isn't one of my
Hi can some one please point out my mistake here. I've got two PHP
This question has been asked few times here and there, but you see all
I made a mistake when I created one of my UIViewController objects. When I
One of my processes is restarting over and over apparently because of following messages
I'm probably blind to my own mistake again, but why doesn't 2011 become the
See the next post. This original one question content has been removed, as doesn't
I can see only one merit of the feauture: we are able to issue
When using python via the command line, if I see a mistake on a
I have several xml files, but I will present only one and the xsd

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.