Simple XML Checker!
Objective:
Write a program that checks whether or not a given file is formatted correctly for a very simple version of XML. In this simple version of XML you have tags that denote information.
Each tag has a "start-tag", and an "end-tag". The start-tag is denoted by a value enclosed by "< >", and the end-tag similarly denoted by "".
Each start-tag must have an end-tag. Elements fall in between the start and end tags, and can also other tags can be nested in as well.
In this version of XML you can assume that tags and elements will always be on separate lines, and no additional attributes (such as id = "3">) will be a part.
Well formatted example
33
Another well formatted example
100
Not well formatted example
44
Another not well formatted example
33
To solve this problem you must:
Write a stack, and use it to solve this problem
You may NOT use the built-in java stack
You may either implement the stack as a linked structure or an array. If you use an array assume the max size is 100;
Write another class that has a main method which takes in a file name and checks whether or not that file is correctly formatted.
Here's a basic idea:
If the next line is enclosed by "< >" with a tag in between, then push the tag onto the stack
If the next line is enclosed by "" with a tag in between, then
Pop one element off the stack
Check if that element matches with end-tag. If it does then continue on, but if it doesn't then it is not formatted correctly
All other values and elements can be ignored
If by the end there are no tags left on the stack then it is properly formatted, but if the stack still has tags then it is not properly formatted.
Also the string methods "charAt(index)" and "substring(startIndex, endIndex)" may be very useful
Here are some files to test with
goodXML1
goodXML2
goodXML3
badXML1
badXML2
badXML3