--------------------------------------------------------------------------------

So i just realized after checking my emial that i have a python hw for my comp sci class due tom night at 12am . I read the hw and i am a bit lost. I will be starting it tonight once i get out of work.

The task is to write a program that check html files to determine if the xhtml tags are balanced using queues and stacks.the first phase will read in the file and find all of the tags and save them into a queue . the second phase will take in the queue of tags from the first phase and check to see if they are balanced and then print the output.

this is how our data file looks:
" This is a paragraph

we're skipping some lines using a self-closing tag

before ending the second paragraph
the next tag is a horizontal-rule which is also self-closing "


this is how the output file looks like'
"
matches

is self-closing
is self-closing
is self-closing
matches
"

Now what are your thoughts about doing this. Obviously ill be using a commandline arguement to make sure that user enters the right files with the excuetable file and a html file to be checked.

I havent had time to experiement with it but ill start tonight. Any help is appreciated. and no im not asking for a whole code, just some thoughts about how to do this so i can type it up fast. puesdocode type deal. thanks.

Recommended Answers

All 3 Replies

I have the same homework and not sure how to even start this.

the first phase will read in the file and find all of the tags and save them into a queue

Wouldn't that just be a list or a dictionary.

the second phase will take in the queue of tags from the first phase and check to see if they are balanced and then print the output.

You can read the stored list, check if each item is an opening tag, search for the corresponding closing tag, and delete both (use a copy of the list if you want to keep the original), and increment a counter if you want to keep track. Whatever is left is what was not matched, either opening or closing tags. Note that in the example file you posted, there were no opening or closing tags so it is difficult to tell what you are working with. If you post the file again, use "[code]" tags to preserve everything, since HTML is scripting code.

If you search DaniWeb, you will find a whole lot of similar requests about queues, stacks and html tag names. Looks like this homework has been given in the last few weeks to a bunch of folks. The Python manual describes the use of queues in detail. Your problem will be to find start and end tags in the html code and shove them onto the stack or queue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.