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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:30:47+00:00 2026-06-08T12:30:47+00:00

Overview Although this question implicates lex/yacc, which are written in C, it’s fundamentally centered

  • 0

Overview

Although this question implicates lex/yacc, which are written in C, it’s fundamentally centered around programming in python.

I have several very similar DTDs that I’m using to parse a document. That section of the program is written in C, and there’s just no need to invoke a full SAX handler (viz., libxml2) for this purpose. Since the DTDs (and therefore the XML files) have a static format, I think that this problem can best be solved with lex and yacc.

While writing a full lexical parser for any XML document is far too complex, writing one for a specific subset of XML documents is entirely manageable. The DTD could be used to generate the lexical analyzer (which tokenizes the input) as well as the parser generator in YACC.

There are two assumptions I am willing to make:

  1. The XML document is well-formed vis-à-vis REC-xml-19980210
  2. The XML document is valid vis-à-vis its DTD

Therefore, if an XML document fails to satisfy any of the above, the lexical analyzer/parser should simply fail for that particular file.

Questions

My ultimate goal is to write a python script that successfully: (1) parses the DTD; and (2)
generates the lex/yacc files. Before I begin, I have several questions:

  1. Has this problem already been solved?
    • If so, are there any libraries that I should consider looking at?
    • If not, is it because there is no solution using the tools I’ve mentioned?
  2. Are there better (as measured by performance) ways to extract the non-markup ‘content’ from XML files than using a static parser?

I realize that I can use PLY to parse the DTD, but because I’m interested in generating the lex/yacc files for inclusion in a C program, that option will not work. As such, I’m thinking that I might use xml.parsers.expat to parse the DTD. This allows me to register callbacks that track the element names, their position within the tree, whether they’re required, etc. This should offer me enough information to generate lex/yacc files, but I would like to see what advice you guys have.

  • 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-06-08T12:30:48+00:00Added an answer on June 8, 2026 at 12:30 pm

    Use a combination of the XML Lexer, the yacc grammar, and the YAXX extension to generate the respective files.

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

Sidebar

Related Questions

So a bit of an overview around the lead up to this exception. I've
Overview I have an iOS app which sends local notifications at specific dates. I
Overview I am using CompositeWPF to create an app using C#. This really should
Overview I have an iOS project which contains 2 navigation controllers as shown in
Overview: I have two text boxes at the top of this form for inputting
Overview: I'm working on some windows service using Visual Basic 2010, which deployed on
I have to make this overview of questions and the user has to be
Overview: I have an Expandable List View which displays items of the type ToDoElement
I've written a simple Scrabble game with a simple Bot and Human part which
There is a conceptual overview of Blocks objects in objective-c within this Apple reference:

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.