Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm not sure I'm doing this right. I'm stuck here. the question is to create Java program named ParseXML to parse XML files. the program

I'm not sure I'm doing this right. I'm stuck here. the question is to create Java program named ParseXML to parse XML files. the program will determin if the XML file inputed is a properly structured XML if not it will print an error message. here is the full question and my attempt. thanks

Your program will implement the following methods:

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;

isWord(String token): This returns true if and only if the token is a word.

isClosingTag(String token): This returns true if and only if the token is a closing tag;

isOpeningTag(String token): This returns true if and only if the token is an opening tag;

isSelfClosingTag(String token): This returns true if and only if the token is a self-closing tag.

public 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.

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

create an empty tag name stack for each token { if (the token is an opening tag) { print token push tag name onto the tag name stack } else if (the token is a closing tag) { print token 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 } } else { print token } } 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 } 

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

An closing tag with no matching opening tag

Improperly nested tags

An opening tag with no matching closing tag

here is my attempt and stuck here:

how do I implement an empty stack and also use that pseudocode ?

import stdlib.*;

import java.io.*

public class ParseXML {

private static BufferedReader buff;

private String token;

public boolean isTag(String token) {

if(token.length() >= 3) {

if(token.charAt(0) == '<' && token.charAt (token.length()-1) == '>')

return true;

}

return false;

}

public boolean isWord(String token) {

return true;

}

public boolean isOpeningTag(String token) {

if(isTag(token)) {

if(token.charAt(1)!='/')

return true;

}

return false;

}

public boolean isClosingTag(String token) {

if(isTag(token)) {

if(token.charAt(1)=='/')

return true;

}

return false;

}

public boolean isSelfClosingTag(String token){

return true;

}

public static void main(String[] args) {

// TODO Auto-generated method stub

}

}

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_2

Step: 3

blur-text-image_3

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

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

Consider this article:...

Answered: 1 week ago