Docsity

XML Parsing Homework Assignment: Implementing a Stack for Well-formed XML Verification - P, Assignments of Computer Science

Toggle sidebar
bg1
1
Homework Assignment 2
Your assignment for Homework 2 is to implement a stack to parse simplified
XML input and verify that the input consitutes well formed XML. This is quite
similar to parsing an algebraic expression to ensure that the open and closing
parentheses have been done correctly. Indeed, many algebraic expressions are
written with three different opening and closing characters: parentheses (and
), “square brackets” [and ], and “curly braces” {and }. XML just allows a
user to generate an essentially infinite variety of opening and closing tokens as
<tag> and </tag> with the string used for tag being almost any text string at
all.
This programming assignment is somewhat less “object oriented” than oth-
ers. Your main program need only declare and then invoke an XLMParser object.
This object should contain a checkValidXML method that takes a Scanner as
a parameter and then returns a boolean
You should use the parsing code done in Lab Assignment 4 to be able to
separate the tokens in the input file into open tokens, close tokens, and data
tokens.
The way to test for valid XML using a stack is this. As you parse the input
file, all open tokens and data tokens should be pushed onto the stack. When
you encounter a close token, you should pop the zero or more data tokens,
saving them in a string, and the first open token that is popped off the stack
should be the open token that matches the close token.
You should implement the stack object using the interface IStack given
here.
public interface IStack
{
/*********************************************************************
* Method to get the ’size’.
* @return the ’int’ value of ’size’
**/
public int getSize();
/*********************************************************************
* Method to pop a node from the top of a stack.
* @param node the ’DLLNode’ to pop.
**/
public DLLNode pop();
/*********************************************************************
* Method to push a node onto the top of a stack.
* @param node the ’DLLNode’ to add.
**/
public void push(DLLNode node);
} // public interface IStack
The actual Stack class can use your DLL from Homework 1. By doing this,
pf2

Partial preview of the text

Download XML Parsing Homework Assignment: Implementing a Stack for Well-formed XML Verification - P and more Assignments Computer Science in PDF only on Docsity!

1

Homework Assignment 2

Your assignment for Homework 2 is to implement a stack to parse simplified XML input and verify that the input consitutes well formed XML. This is quite similar to parsing an algebraic expression to ensure that the open and closing parentheses have been done correctly. Indeed, many algebraic expressions are written with three different opening and closing characters: parentheses ( and ), “square brackets” [ and ], and “curly braces” { and }. XML just allows a user to generate an essentially infinite variety of opening and closing tokens as and with the string used for tag being almost any text string at all. This programming assignment is somewhat less “object oriented” than oth- ers. Your main program need only declare and then invoke an XLMParser object. This object should contain a checkValidXML method that takes a Scanner as a parameter and then returns a boolean You should use the parsing code done in Lab Assignment 4 to be able to separate the tokens in the input file into open tokens, close tokens, and data tokens. The way to test for valid XML using a stack is this. As you parse the input file, all open tokens and data tokens should be pushed onto the stack. When you encounter a close token, you should pop the zero or more data tokens, saving them in a string, and the first open token that is popped off the stack should be the open token that matches the close token. You should implement the stack object using the interface IStack given here.

public interface IStack { /*********************************************************************

  • Method to get the ’size’.
  • @return the ’int’ value of ’size’ **/ public int getSize(); /*********************************************************************
  • Method to pop a node from the top of a stack.
  • @param node the ’DLLNode’ to pop. **/ public DLLNode pop(); /*********************************************************************
  • Method to push a node onto the top of a stack.
  • @param node the ’DLLNode’ to add. **/ public void push(DLLNode node); } // public interface IStack

The actual Stack class can use your DLL from Homework 1. By doing this,

2

the push method can simply use the existing addFirst method to push a node onto the stack, and the pop method can simply return the head node of the DLL. (Remember to unlink the head node as well.) Creating a stack is thus the easy part of this program; the hard part of the program is to use the stack to verify correctness of the input file.