Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are going to develop a program named ParseXML to parse XML files. This means that your program will determine whether an input XML file

You are going to develop a program named ParseXML to parse XML files. This means that your program will determine whether an input XML file is properly structured and, when not so, print informative error messages.

Requirements

Your program will implement the following public static methods:

  • public static boolean isTag(String token): This returns true if and only if the token passed as a parameter is a tag, as opposed to being a word;
  • public static boolean isWord(String token): This returns true if and only if the token is a word.
  • public static boolean isClosingTag(String token): This returns true if and only if the token is a closing tag;
  • public static boolean isOpeningTag(String token): This returns true if and only if the token is an opening tag;
  • public static String tagName(String token): This returns the name of a tag, that is, the alphanumeric text appearing between the angle brackets. It should return a null if the token is not a tag.

Syntactically correct XML

A properly formed XML document is such that:

  • Every opening tag is followed at some point by a closing tag with the same tag name.
  • Opening and closing tags are properly nested. For example, assume the following tags appear in the document:
     
    They must eventually be followed first by a tag and then a tag.

Between tags may be any text not containing a less-than character or a greater-than character.

Your program will read an XML file from a file specified by the user and, as it does so, it will parse it using the algorithm specified below and by calling at various points the methods written above.

Parsing algorithm

Your main method will contain an implementation of the following pseudocode algorithm:

prompt the user for the filename of the XML file read all of the strings into tokens, which is an array of strings create an empty tag name stack for each token in tokens { print the token if (the token is an opening tag) { push tag name onto the tag name stack } else if (the token is a closing tag) { if (the tag name stack is empty) { print an error message that a closing tag has no matching opening tag and print that closing tag exit the program } pop tag name off tag name stack if (the token's tag name is not equal to the popped tag name) { print an error message that a closing tag does not match its opening tag and print that closing tag exit the program } } } if (the tag name stack is not empty) { print an error message that there are opening tags with no matching closing tags and print all of those opening tags else { print a message that the XML is correct } 

Notice in the pseudocode that are there are three possible errors:

  1. A closing tag with no matching opening tag
  2. Improperly nested tags
  3. An opening tag with no matching closing tag

This XML test file has a closing tag that doesn't match the most recent opening tag:

image text in transcribed

JAVA, PLEASE

XML test file 2 John Doe
111 Elm Street Joliet Illinois 60435 address
XML test file 2 John Doe
111 Elm Street Joliet Illinois 60435 address

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

What has been your desire for leadership in CVS Health?

Answered: 1 week ago

Question

Question 5) Let n = N and Y Answered: 1 week ago

Answered: 1 week ago