XML Final Skima

Embed Size (px)

Citation preview

APR 2010 PART A (60 MARKS) QUESTION 1 XML can be designed and used in various kinds of application. MathML is one of the examples of language based on XML. In order to create an XML, an author needs to be aware of the syntax rules to make an XML document well-formed. a) List FOUR (4) main syntax rules of XML that meet the well-formedness constraint given by the XML 1.0 specification. (2 marks) y y y y y XML Elements must have a Closing Tag XML Tags are Case sensitive XML Elements Must be properly Nested XML document must have a Root Element XML Attribute must be Quoted

b) Describe what is meant by this statement: "XML is a metalanguage". (2 marks) y Xml can be used to describe and generate other language markup

c) List TWO (2) XML-based languages listed in W3C Recommendation. (1 mark) y d) Based on the answer in c), list the domain or field of each the language. (1 mark) y

QUESTION 2 a) DTD is abbreviation for Document Type Definitions. Define the purpose of DTD. (2 marks) y Defined the structure of an XML document with a list of legal elements. b) Write a DTD statement based on the following condition: i) Declare an element named bag that contains either element vegetable or element fruit, but not both. ii) Declare an element named bag that contains the element vegetable, or the element fruit, or both of them in the sequence vegetable, fruit. iii) Declare an element named bag that contains two elements of vegetable or two elements of fruit in the sequence. (6 marks)

QUESTION 3 Write XML Schema Definition (XSD) codes to define the following elements/attributes: a) Simple type element named ClassName. The values for ClassName start with a number, followed by six letters of the alphabet in capital letters. (2 marks)

b) Simple type element named Passwd. Passwd consists of eight characters which contain any combination of numbers, uppercase letters and/or lowercase letters. (2 marks) c) Attribute named state . The values of stat e may only contain Selangor, Perak or Johor. (2 marks) d) Complex type element named Order. Order contains mixed content. The child elements of Order are Orderid , Date, and Quantity . Orderid contains positive integers. Date contains date, while Quantity contains numbers. All the child elements must appear in the following sequence: Orderid , Date and Quantity . (3 marks)

QUESTION 4 Given the following XML document which consists of data about lecturers of FSKM and their Special Interest Group (SIG):

a) Write an XPath expression to select all CS lecturers (cs) with name Rosnah. y /FSKM/CS_lec//cs[name= Rosnah ]

b) Write an XPath expression to select the text of the name for the second cs element. y /FSKM/CS_lec/cs/name[2]

c) Write an XPath expression to select the SIG (sig ) of all CTN_lec. y /FSKM//CSTN_lec/ctn/sig

d) Write an XPath expression to select the SIG for CS_lec named Mariam. y /FSKM/CS_lec/cs@sig[name= Mariam ]

e) Write an XPath expression to select the third lecturer of FSKM (FSKM). (10 marks) y

QUESTION 5 Document Object Model (DOM) represents an XML document as a tree or hierarchy of node objects. The node interface is the primary datatype for the entire DOM. a) List FOUR (4) basic types of nodes used to represent XML document components. (4 marks) y element y attribute y text y comment y document note b) List FIVE (5) names and their description of the node properties used in W3C. (5 marks) y nodeName specifies the name of node y nodeValue specifies the value of a node y nodeType return the type of node. y childNodes returns a nodelist of child nodes for a node y nextSibling return the node immediately following a node y fistChild return the first child of a node y lastChild return the last child of node. c) Given an XML document that contains data about student's information in their class.

Create a DOMDocument object to load in the XML document the name of the third student. Given below is a segment of JavaScript for you to fill in.

function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(); return xhttp.responseXML; } xmlDoc=loadXMLDoc("student.xml"); function readData() { first=xmlDoc.getElementsByTagName("firstName")[2].childNodes[0].nodeValue; last=xmlDoc.getElementsByTagName("lastName")[2].childNodes[0].nodeValue; document.write(first + " " + last + "
"); }

QUESTION 6 Write the XSL code to produce the HTML output from the XML file.

PART B (40 MARKS) QUESTION 1 Given the following XML and DTD documents:

a) Write an XSL Stylesheet to transform the given XML document to the following XML document: Please take note that the values for the attributes are NOT constants. They are captured from the XML document. (10 marks)

b) Write an XSL Stylesheet to transform the given XML document to an HTML file that will display a table on a browser with the following information:

Sort the table by date in descending order. (8 marks)

LOGBOOK Session Date Type Heart Rate

QUESTION 2 Given the structure of an XML data as follows:

a) Write an XML Schema Definition (XSD) to define the structure above based on the following restrictions: Both Animal s and Plant s elements must occur at least once. Fruit and vegetable elements may occur zero or more times. Animal s must only contain the values: chicken, duck, and/or goat. Fruit must only contain the values: rambutan, mango, and/or papaya. Vegetable must only contain the values: cabbage and/or chili. (8 marks)

b) Write a possible XML document based on the XML Schema Definition created above. (4 marks) chicken duck goat rambutan mango papaya chili cabbage

QUESTION 3 Given an XML document, named person.xml as follow:

In order to display the output, write an XSLT Stylesheet by using element so that you can choose the specific elements to be formatted. Below is the guideline of data format:

Element name - font: arial bold, text alignment: right Element address - font: arial 12, text alignment: right Element cit y - font: arial 12 bold, text alignment: right Element icnumber - font: vendana 10, text alignment: justify Element emai l - font: vendana 10 italic, text-alignment: justify (10 marks) Person Info

Name:
Address:
City:
IC number:
Email:

OCT 2010 PART A (60 MARKS) QUESTION 1 Diagram below illustrates the relationships between markup languages.

a) Define the term "metalanguage". (2 marks) y b) Describe the concept of "markup". (2 marks) y c) Describe the relationship between HTML and XML. (2 marks) y d) State TWO differences between HTML and XML. (4 marks) y e) State a different between valid and well-formed. Write ONE (1) example for each of them. (3 marks) y

QUESTION 2 Content models are used to indicate the structure and order in which child elements can appear within their parent element. a) Describe the meaning of three types of model group listed below: i) xsd : sequence y meaning that the elements must show up in the order they are declared ii) xsd:al l y meaning that the elements can chow up in any order iii) xsd : choice y meaning that only one of the child elements may show up (6 marks) b) For each type of the content models above, write a valid XML code with XML Schema. (9 marks) i)

ii) iii)

QUESTION 3 The definition for document type, my-doc.dt d contains the following markup declarations. By considering the DTD below:

a) Replace and write the text of entity my-style with the equivalent text in DTD. (3 marks) y (#PCDATA | big | small | em | cite)*

b) Write a well-formed and valid example for element my-Para. In addition, the element my-Para is required to have TWO children elements and TWO attributes. (5 marks) y my-Para (#PCDATA | big | small | em | cite) is of mixed type Dari Anas RA Nabi SAW bersabda> tidak sempurna keimanan seseorang dari kalian, sebelum ia mencintai saudaranya (sesame muslim) sebagaimana I mencintai dirinya sendiri.

QUESTION 4 The Document Object Model (DOM) is a language-independent alternative. It views XML documents as a tree-structure and all the elements, text and attributes are known as nodes. Given below are an XML document and a segment of JavaScript code used to load the XML file.

State the output return from the DOM reference code below. a) xmlObj .childNodes(3).hasChildNodes() y return TRUE b) xmlObj .childNodes(2).hasChildNodes() y Return FALSE c) xmlObj.tagName y Return school d) xmlObj .childNodes(0).tagName y Return Teacher e) xmlObj .childNodes(3) .childNodes(0).tagName y Return Enrollment f) xmlObj childNodes(0) .firstChild.text y Return Suriati Mokhtar g) xmlObj .childNodes(3) .childNodes(1).firstChild.text y Return 40 h) xmlObj .childNodes(1).getAttribute("age") y Return 24

QUESTION 5 Given below is an XML document.

Write the output extracted from the following XPath expression: a) x | y/ x y Green yellow blue purple orange gray cyan brown b) // x y Green yellow blue black red purple orange grey cyan brown c) // y y Yellow blue orange grey cyan brown d) y[1] / x[2 ] y blue e). x[3 ] / y[2 ] y grey f) (x/y ) [1] y orange g) x / y[1] y orange cyan h) x / y [position n () = 1] y orange cyan

QUESTION 6 Given below are the DTD and HTML document. By considering the DTD below, write an XSLT coding to transform any XML document that has the structure described by the DTD to produce the following HTML document. The data in the HTML document is sorted by name/first.

xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transfom" version="1.0" xmlns="http://www.w3.org/1999/xhtml"> Business card email:

PART B (40 MARKS) QUESTION 1 Given below is a list of integer number written in XML document. Write an XSLT Stylesheet code to transform the data in XML into a sorted list of data in ascending order with alternating font color red and blue.

QUESTION 2 XML document below contains data related to car manufacturing.

Write an internal DTD to validate the XML document above by adding the requirement listed below. - an optional text string attribute "id " for the element CATEGORY. - an attribute named "discount " for element PRIC E which can have one of four possible values: 10, 20, 30 and 40. - a "code" attribute is required for element MODEL with the value must contain no white space. - an element ITEM_NAM E has an optional attribute named "product", which refer to the "id " item of the name of CATEGORY. - The element COMPONENT has an optional attribute named "instock " that can have the value "yes" or "no". The default value is "yes". (15 marks)

]>

QUESTION 3 Given the hierarchy structure of an XML data as below:

a) Write an XML Schema Definition (XSD) to define the structure above based on the following restrictions: PatRec element can occur one or more Gender only acceptable value is male OR female ProcedureCost has a value of at least RM15.00 but cannot exceed the value of RM2,500.00 MedTest element only acceptable value is xRay OR blood OR urine" (10 marks)

b) Write any possible XML document based on the XML Schema Definition created above. (5 marks)

APR 2011 PART A (60 MARKS) QUESTION 1 XML can be designed and used in various kinds of applications. Supposed an XML application uses an XML document named stocks.xml; a stylesheet file named stock s.xsl ; and an external DTD named stocks.dtd . Write the first THREE (3) instructions in the XML document to show how these files are linked to one another. The root element is named . (6 marks)

QUESTION 2 The XML document must have a consistent and well-defined structure. There are a numbers of rules that need to be considered to make sure that the XML document conforms with the well-formedness constraints. State whether the element below is legal, illegal and depending on the XML parser you use for the XML names. a) y legal b) y legal c) y illegal d) y illegal e) y legal f) y depending on XML parser g) y depending on XML parser (1 mark) (1 mark) (1 mark) (1 mark) (1 mark) (1 mark) (1 mark)

QUESTION 3 Attributes are used to associate name-value pairs with elements. Describe the value of an attribute for: a) ID type (2 marks) y Attribute ID type can contain only character permitted for NMTOKEN and must start with a letter. No element type may have more than one ID attribute specified. The value of an ID attribute must be unique between all values of all ID attributes. b) NMTOKEN type (2 marks) y Can contain only lettersm digits and point[.], hypen[-], underline[_] and colon[:] c) NMTOKENS type (2 marks) y Can contain the same characters as NMTOKEN plus whitespaces. White spaces consists one or more space characters, carriage returns, line feeds, or tabs d) IDREF type (2 marks) y The value of IDREF attribute must match the value of some ID attribute in the document e) IDREFStype (2 marks) y The value of IDREFS attribute can contain the value of some ID attributes separated with witespaces

QUESTION 4 Given below is the following XML document. Write a DTD that describe the XML below where the attributes i d and mark uniquely determine their element and the attributes re f refer to these elements.

]>

QUESTION 5 An XML Schema is a road map for the XML document that similar to a Document Type Definition (DTD) and created by the World Wide Web Consortium (W3C). DTD and XML Schema are used for an XML page and accomplish some of the same goals. a) Describe ONE (1) reason of why we are using XML Schema. (2 marks) y A schema is a blueprint of an xml document that defines the element, data types and nesting structure of the page y Schemas allow all applications to understand the rules and content of the page b) State ONE (1) advantage using XML Schema as compared to DTD. (2 marks) y XML schema have built-in datatypes y XML schema do support user-derived datatypes y XML schema DTDs able to control over cardinality (number of occurrences of an element within its parents). c) Define a complex type in XML Schema. Give ONE (1) example to justify the answer. (4 marks) y Complex type is an XML element that may have other XML elements and attributes within it. d) Define a simple type in XML Schema. Give TWO (2) examples to justify the answer. (6 marks) y Elements that do not contain any other elements. y Can only contain data y These are the meet of the XML document, as they contain the actual data that is being defined. y xs:positiveInteger o An integer is any whole number, and a positive integer is any number not zero or negative. For the web writer newsletter, I needed t o have whole numbers to describe the volume and number of each issue. Xs:date o Number values of a year, month, and day in the following format: YYYY-MM-DD.

y

e) Write a corresponding Schema definition based on a snippet of XML coding given below. Apa khabar, saudara? (3 marks)

QUESTION 6 Consider the following DTD fragment: Write down absolute XPath expressions for the following queries on a document valid with respect to the above DTD fragment and with books as its root element: a) Find book(s) which have more than 2 author(s). (4 marks) y /books/book[count(author)>2] b) Find book(s) which have an isbn and all author elements have a first-name specified. (4 marks) y //book[isbn][not(author[not(first-name)])]

PART B (40 MARKS) QUESTION 1 Many companies are in the position of being aware of Business-to-Business (B2B) e-Commerce, but have questions about some of the basic concepts, and more importantly, the benefits of becoming involved in B2B processes with their trading partners, those being most commonly customers and suppliers. In the long run, XML may become a common thread uniting a wide variety of applications. Describe FOUR (4) points on how XML will benefit B2B environment. (8 marks) y Data can be exchange between incompatible system o Greatly reduce its complexity y Financial information can be exchange over the internet o Prospect for B2B y Plain text file can be used to share data o Xml provide a software and hardware independent way of sharing data y Data is more available to more users o Other client and application can access xml file as data sources. y Can create a new languages y Is a mother of WAP an WML

QUESTION 2 Consider using an XML document to represent a person's batik collection. The collection consists of one or more batik. Each batik contains a name, a price and an optional clot h material (i.e., Kelantan's silk). Each batik is a type of "tulis" or "cop" and this additional information must be provided for each batik. A batik also comprises zero or more color , each with an optional count associated with it (having zero count is interpreted as not knowing the number of color used). The price is described by quantity which is either per piece or per bundle and the default being per piece . a) Write a Document Type Definition (DTD) which satisfies the requirements described above. (7 marks)

b) Write an XSL Stylesheet to transform the XML document to an HTML form that will display a table on a browser with the following information:

Sort the table by name in ascending order.

(10 marks)

BATIK COLLECTION NAME Price Quantity

QUESTION 3 Given below is XML document that contains information about collection. Write an XML Schema that will conform to the XML document plus with additional requirements mentioned below

In the XML document, a collectio n consists of an arbitrary number of Book and CD elements in any order. Below are the details of the requirements: A Book has children elements called Title , Author, Type, Published , and optionally Rating and/or Notes. A CD has a Title , Artist , one or more Labe l elements and AlbumReleased date, and one or more Remastered dates. The element Name (and its children, Firs t and Last) is used both for a book Author. Titl e element applies to both Book and CD. All attributes except Remastered have default values specified. Declare an attribute named versio n of string type with a fixed value of "2". A sex attribute constrained to be an xsd : NMTOKEN with only two possible values which are "male" and "female" . (15 mark)