Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Work so far can be found at the very bottom. Cannot use and private(). Problem 2: XML XML, the Extensible Markup Language, is a ubiquitous

Work so far can be found at the very bottom. Cannot use and private().

image text in transcribedimage text in transcribed
Problem 2: XML XML, the "Extensible Markup Language", is a ubiquitous format for exchanging data on the internet. It is also used extensively in modern office-productively software produced by Microsoft, Apple, and the open-source community. XML is fairly simple: it consists of content that is "marked up" with tags. Here are some simple examples of XML: I am XML! The above is just plain content with no tags. We can tag certain parts of the content with a pair of open and close tags to delimit the tagged region: I am XML! Here the content XML is tagged with the yell tag. The tags can nest, as in: I am XML! Here the content XML is again tagged with yell, but the X is also tagged with the italic tag. Tags can also carry attributes that associate data with a tag. For example, we may want to yell at a certain volume: I am XML! Here the yell tag carries a volume attribute with the value 30db. Moreover, you can add an arbitrary number of attributes to a tag, so we can specific both the volume and the duration of a yell: I am XML! If we step back and think about how to represent XML, we arrive at the following sketch: XML is either just plain content (no tags), or it is tagged XML, i.e. it is some tag, some list of attributes and values, and some XML. The following DrRacket data definition describes XML: ; ; An XML is one of : (make-plaintext String) ( make-untagged [Listof XML]) ( make-tagged Tag [Listof XML]) ; ; A Tag is a (make-tag String [Listof Att]) ; ; An Att is a (make-att String String) (define-struct plaintext (txt) ) (define-struct untagged (content) ) (define-struct tagged (tag content) ) (define-struct tag (name atts) ) (define-struct att (name value) )Define Java classes that represent XML as defined above. Translate all of the above examples using your representation. Name your examples class ExamplesXML. Name your examples ml 1, xm12, etc. Note that the Untagged constructor should only be called when absolutely necessary. Design a content Length method which computes the length (number of characters) of the content in an XML document. The tags and attributes should not contribute to the length. Design a hasTag method that determines if a piece of XML contains a Tag with the given name. Design a hasAttribute method that determines if a piece of XML contains an attribute with the given name. Design a renderAsStrin g method that converts XML to a String without tags and attributes. HINT: We asked you to implement renderAsString but you might want to also implement renderAsXmlStrin g which includes the tag names and attribute names. That way you can check if your data matches our examples! This is more coding work that will save you debugging work

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions