An XML file contains tags, which are used to indicate the structure of the data
ID: 3762654 • Letter: A
Question
An XML file contains tags, which are used to indicate the structure of the data represented in the file. There are many tutorials and explanations of XML. Two to consider are the W3 Schools tutorial and the Wikipedia article on XML An XML file is a text file made up of tokens, that is, individual strings separated from each other by whitespace. A token is either a word or it is a tag. A token is a tag if and only if it is bounded by angle brackets, e.g., . There are two types of tags: * If the second character (the one just after the left angle bracket) is alphabetic, this is an opening tag. If the second character is a forward slash (e.g., ), this a closing tag The tag name is the alphanumeric text inside between the angle brackets that does not include the slashes. In other words, except for the slash in a closing tag, the only characters that may appear between the brackets are letters, numerals, and hyphens. This means, for example, that the string is neither a tag nor a word. It should not appear in an XML file Setting up First, please read the section "Assignments and grading" in the syllabus. Then, following the steps for creating programs, create a package called parseML. Specifications First, write a reference class called YMLToken to represent a token object. It will have only one instance variable, which is the token string itself. It will have the following constructor and instance methods: public XMLToken (String token) : This creates an XMLToken object and initializes the instance variable with the string parameter passed public boolean isTag ) This returns true iff the token is a tag, that is, it contains at least three character and the first and last characters are public boolean isopeningTag ) : This returns true iff the token is an opening tag * public boolean isClosingTag ) This returns true iff the token is a closing tag public String getTagName ) For a tag, this returns the tag name, that is, the alphanumeric text inside the tag. If the token is not a tag, this returns the empty string "". Next, write a program called CountTokens that: 1. Prompts the user for the pathname of a file; 2. Redirects StdIn to read from that file 3. Reads in the file's contents token by token (where tokens are separated by whitespace) and, for each token: o creates an XMLToken object; o adds the object to the end of an array list of XML tokens. 4. Iterates throught the array list to count the number of words, opening tags, closing tags, and malformed tokens (that is, any token that is neither a word nor a tag) 5. Prints the counts with explanatory text.Explanation / Answer
An HTML file could contain this form asking the user for a word to look up:
Or the HTML file could contain this server-side include:
No matter what the HTML looks like or whether the servlet handles GET requests, POST requests, or server-side include requests or is part of a filter chain, you can use code like the following to retrieve the servlet's parameters:
While this code works fine, it can handle only one word per request. To handle multiple values for word, the servlet can use the getParameterValues() method instead:
In addition to getting parameter values, a servlet can access parameter names using getParameterNames() :
This method returns all the parameter names as an Enumeration of String object or an empty Enumeration if the servlet has no parameters. The method is most often used for debugging.
Finally, a servlet can retrieve the raw query string of the request with getQueryString():
This method returns the raw query string (encoded GET parameter information) of the request or null if there was no query string. This low-level information is rarely useful for handling form data. It's best for handling a single unnamed value, as in "/servlet/Sqrt?576", where the returned query string is "576".
Example 4-7shows the use of these methods with a servlet that prints its query string, then prints the name and value for all its parameters.
Example 4-7. Snooping parameters
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.