Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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.

Heres 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 doesnt 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

Example Dialog:

Welcome to the simple XML tester. Time to test simple XML's

Enter a file name

goodXML1.txt

This XML File was formatted correctly

Another Example Dialog:

Welcome to the simple XML tester. Time to test simple XML's

Enter a file name

badXML1.txt

This XML file is not formatted correctly

The tag "bad" does not have a match

Yet Another Example Dialog:

Welcome to the simple XML tester. Time to test simple XML's

Enter a file name

badXML3.txt

This XML File was not formatted correctly

The following tags didn't have an end tag

super really bad

really bad

bad

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago