Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please explain how to define the Java classes that define XML and translate from the definition. Also, if possible, draw a class diagram explaining this

image text in transcribedimage text in transcribedimage text in transcribed

Please explain how to define the Java classes that define XML and translate from the definition. Also, if possible, draw a class diagram explaining this as well please. Please don't do the methods for this problem.

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 officc-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: 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 x italic > ML ! 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 specifiy both the volume and the duration of a yell: 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: 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)) We are giving you the names of the classes or interfaces you will need - make sure you use these names to define your interfaces and classes A reminder on naming conventions: For lists of data, the names of the interface should always start with ILo, while the two classes' names start with MtLo for the empty lists and ConsLo for the nonempty lists; all three of these names should be followed by the name of the datatype of the elements of the list. So we would have ILostring, MtLostring, ConsLostring to represent lists of Strings, ILoBook, MtLoBook, ConsLoBook to represent lists of Books, etc. - Draw a class diagram for the classes that represent this data definition on a piece of paper. You do not have to submit this, but this is the first assignment with a complex class structure, and understanding it is essential before proceeding. - 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 xml1, xml2, etc. Note that the Untagged constructor should only be called when absolutely necessary. - Design a contentlength 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 aturibute with the given name. We are giving you the names of the classes or interfaces you will need - make sure you use these names to define your interfaces and classes A reminder on naming conventions: For lists of data, the names of the interface should always start with ILo, while the two classes' names start with Mt Lo for the empty lists and ConsLo for the nonempty lists; all three of these names should be followed by the name of the datatype of the elements of the list. So we would have ILostring, MtLostring, Conslostring to represent lists of Strings, ILoBook, MtLoBook, ConsLoBook to represent lists of Books, etc. - Draw a class diagram for the classes that represent this data definition on a piece of paper. You do not have to submit this, but this is the first assignment with a complex class structure, and understanding it is essential before proceeding. - 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 xml1, xmi2, etc. Note that the Untagged constructor should only be called when absolutely necessary. - Design a contentlength 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 renderasstring 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 renderAsXmLString which includes the tag names and atcribute names. That way you can check if your data matches our examples! This is more coding wark 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

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions