Question

The following XML document describes a selection of books from a library. <?xml version="1.0" encoding="UTF-8" ?>...

The following XML document describes a selection of books from a library.

<?xml version="1.0" encoding="UTF-8" ?>

<!-- file name: library.xml -->

<library>

<book category="COOKING">

<title lang="en">My Kitchen Year</title>

<author>Ruth Reichl</author>

<year>2015</year>

<price>35.00</price>

<pages>352</pages>

</book>

<book category="CHILDREN">

<title lang="en">Harry Potter</title>

<author>J. K. Rowling</author>

<year>2005</year>

<price cover="soft">29.99</price>

</book>

<book category="XML">

<title lang="en">XQuery Kick Start</title>

<author>Brian Benz</author>

<author> John Durant</author>

<year>2003</year>

<price cover="hard">149.99</price>

<pages>984</pages>

</book>

<book category="XML">

<title lang="en">XML Primer</title>

<author>

Nicholas Chase</author>

<year>2002</year>

<price>39.95</price>

<pages>1024</pages>

<description> I highly recommend this book. It's a

<emphasis> good intro book to XML </emphasis>, which

is what it's intended to be.</description>

</book>

</library>

1. Check if the XML document is well-formed. If it is not, change it so that it becomes

wellformed, making as little changes as possible.

2. Write a DTD for this XML document such that the corrected version of the example is

a valid XML document, taking into account that the attribute

cover

is optional with

values “soft” or “hard”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<?xml version="1.0" encoding="UTF-8" ?>

<!-- file name: library.xml -->
<!DOCTYPE library [
<!ELEMENT library (book+)>
<!ELEMENT book (title,author+,year,price,pages?,description?)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ELEMENT pages (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ATTLIST book category CDATA >
<!ATTLIST title lang CDATA >
<!ATTLIST price cover (soft|hard) #IMPLIED >
]>


<library>

<book category="COOKING">

<title lang="en">My Kitchen Year</title>

<author>Ruth Reichl</author>

<year>2015</year>

<price>35.00</price>

<pages>352</pages>

</book>

<book category="CHILDREN">

<title lang="en">Harry Potter</title>

<author>J. K. Rowling</author>

<year>2005</year>

<price cover="soft">29.99</price>


</book>

<book category="XML">

<title lang="en">XQuery Kick Start</title>

<author>Brian Benz</author>

<author> John Durant</author>

<year>2003</year>

<price cover="hard">149.99</price>

<pages>984</pages>

</book>

<book category="XML">

<title lang="en">XML Primer</title>

<author> Nicholas Chase</author>

<year>2002</year>

<price>39.95</price>

<pages>1024</pages>

<description> I highly recommend this book. It's a

<emphasis> good intro book to XML </emphasis>, which

is what it's intended to be.</description>

</book>

</library>

Add a comment
Know the answer?
Add Answer to:
The following XML document describes a selection of books from a library. <?xml version="1.0" encoding="UTF-8" ?>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation,...

    Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation, some basic methods and properties and an xml file on bookstore which we discussed this week. Wite two func- tions; First, write a recursive Python function get_text(elm) to extract all the text of a dom tree pointed by elm. For example, get_text(elm), where elm=<bookstore>, will return [[u'Emacs User Manual', u'Richard Stallman', u'1980', u'12.00'], [u'Timeline', u'Michael Chricton', u'1999', u'15.00'], [u'Catch 22', u'Joseph Heller', u'1961', u'20.00'],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT