















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A set of practice questions and answers related to xml (extensible markup language), covering topics such as xml structure, dtds (document type definitions), xml schema (xsd), xpath, and xslt. It is designed to help students and professionals test their knowledge and prepare for xml-related exams or certifications. The questions cover fundamental concepts, syntax, and usage of xml technologies, making it a valuable resource for learning and review. The practice exam includes questions on well-formedness, xml declarations, cdata sections, root elements, entities, attribute types, content models, external dtd references, xsd data types, facets, and xpath expressions. It also covers xslt elements and instructions for transforming xml documents. This practice exam is a useful tool for anyone looking to enhance their understanding of xml and related technologies.
Typology: Exams
1 / 87
This page cannot be seen from the preview
Don't miss anything!
















































































Question 1. Which of the following best describes the primary purpose of XML? A) To define the visual layout of web pages B) To provide a platform‑independent way to describe data structures C) To replace all programming languages D) To enforce strict data types without schemas Answer: B Explanation: XML is a metalanguage designed to describe data in a platform‑independent, extensible way, separating content from presentation. Question 2. In XML, which statement about well‑formed documents is correct? A) They must conform to a DTD or XSD B) They may contain multiple root elements C) All tags must be properly nested and closed D) Attribute values can be unquoted if they contain no spaces Answer: C Explanation: Well‑formedness requires proper nesting, a single root element, and quoted attribute values, but does not require a DTD or XSD. Question 3. What is the correct XML declaration for a UTF‑8 encoded document? A) B) C) D) Answer: C Explanation: The XML declaration must use double quotes for attribute values and the correct case for the encoding name.
Question 4. Which of the following XML constructs is used to include raw text that should not be parsed as markup? A) B) ... ?> C) D)
Question 10. What does the DTD content model (title, (author|editor)+, body?) specify? A) title must be followed by exactly one author or editor, then optional body B) title, then one or more author or editor elements, then optional body C) title, optional author, required editor, optional body D) title and body are mandatory, author or editor are optional Answer: B Explanation: The sequence indicates title, then one or more occurrences of either author or editor, and an optional body element. Question 11. Which DTD declaration defines an attribute “id” that must be unique within the document? A) id CDATA #REQUIRED B) id ID #REQUIRED C) id ID #IMPLIED D) id NMTOKEN #FIXED "123" Answer: B Explanation: The ID type enforces uniqueness across the entire XML document. Question 12. In an external DTD reference, which syntax is correct? A) B) C) D) Answer: A Explanation: The SYSTEM identifier is used to reference an external DTD file by its URI.
Question 13. Which of the following XML Schema (XSD) data types is derived from the primitive type xs:string? A) xs:normalizedString B) xs:dateTime C) xs:integer D) xs:boolean Answer: A Explanation: xs:normalizedString is a restriction of xs:string that disallows line breaks. Question 14. In XSD, which facet restricts a string to a specific pattern? A) enumeration B) length C) pattern D) maxInclusive Answer: C Explanation: The pattern facet uses a regular expression to limit allowed string values. Question 15. Which XSD built‑in type would you use to represent a monetary amount with two decimal places? A) xs:decimal B) xs:float C) xs:string D) xs:gYearMonth Answer: A Explanation: xs:decimal provides arbitrary precision decimal numbers and can be constrained with totalDigits/fractionDigits facets.
Explanation: xs:include merges schemas with identical target namespaces, while xs:import is for different namespaces. Question 19. Which XSD attribute indicates that an element can contain both child elements and character data? A) mixed="true" B) content="mixed" C) type="xs:mixed" D) mode="mixed" Answer: A Explanation: The mixed="true" attribute on xs:complexType enables mixed content models. Question 20. Which of the following XPath expressions selects all
Answer: B Explanation: The ancestor axis returns all nodes that are ancestors (parents, grandparents, etc.) of the context node. Question 22. Which XPath shorthand notation is equivalent to “child::node()”? A). B) // C) / D) * Answer: C Explanation: The single slash selects child nodes of the current context; it is shorthand for child::node(). Question 23. What does the XPath function string-length() return when called with no argument? A) The length of the current node’s name B) The length of the string value of the context node C) Zero D) An error because an argument is required Answer: B Explanation: When omitted, the function uses the string value of the context node as its argument. Question 24. In XSLT, which element is used to match nodes in the source document? A) <xsl:template> B) <xsl:apply-templates> C) <xsl:for-each>
Answer: B Explanation: XSLT 2.0 aligns with XPath 2.0, adding richer data types and functions. Question 28. In an XSD, which facet would you use to ensure an integer element is at least 10? A) minInclusive="10" B) minExclusive="9" C) maxInclusive="10" D) pattern="[1-9][0-9]*" Answer: A Explanation: minInclusive defines the lowest permissible value inclusive of the bound. Question 29. Which of the following is true about XML namespaces? A) They are declared using the xmlns attribute on any element B) They can only be declared on the root element C) They replace the need for DTDs D) They must be URLs that resolve to a schema file Answer: A Explanation: The xmlns attribute (or xmlns:prefix) can appear on any element to declare a namespace scope. Question 30. What does the XML Schema attribute targetNamespace define? A) The namespace of the schema document itself B) The namespace of the instance documents that the schema validates C) The default namespace for all child elements in the schema D) The namespace for imported schemas only
Answer: B Explanation: targetNamespace specifies the namespace that instance elements must belong to for the schema to apply. Question 31. Which XSD element is used to define an attribute that must contain a list of IDs? A) <xs:attribute name="ids" type="xs:IDREFS"/> B) <xs:attribute name="ids" type="xs:IDREF"/> C) <xs:attribute name="ids" type="xs:list"/> D) <xs:attribute name="ids" type="xs:ID"/> Answer: A Explanation: xs:IDREFS is a space‑separated list of IDREF values. Question 32. In XPath, how would you select the last
D) It creates a new element named chapter with attribute number="1" Answer: B Explanation: xsl:apply-templates selects nodes matching the XPath expression and invokes templates that match those nodes. Question 37. In XPath, which node test would select any element regardless of its name? A) node() B) * C) element() D) text() Answer: B Explanation: The wildcard * matches any element node. Question 38. Which of the following is a correct way to declare a parameter entity in a DTD? A) %myParam; B) C) D) %!ENTITY myParam "value"> Answer: B Explanation: Parameter entities are declared with and referenced as %name;. Question 39. In XSD, what does the attribute abstract="true" on a complexType indicate? A) The type cannot be used directly to validate elements; it must be extended or restricted B) The type is hidden from the generated Java classes C) The type is deprecated and should not be used D) The type can only be used for attributes, not elements
Answer: A Explanation: An abstract type serves as a base for other types but cannot appear directly in instance documents. Question 40. Which XPath axis selects the following-sibling nodes of the context node? A) preceding-sibling:: B) following-sibling:: C) sibling:: D) child:: Answer: B Explanation: The following-sibling axis returns nodes that share the same parent and appear after the context node. Question 41. In XSLT, which attribute of <xsl:template> defines the priority when multiple templates match the same node? A) mode B) priority C) match D) name Answer: B Explanation: The priority attribute assigns a numeric value that resolves conflicts among matching templates. Question 42. Which XSD built‑in type would you use for an element that must contain a valid URI? A) xs:anyURI b) xs:string
B) attribute::* C) ./@* D) All of the above Answer: D Explanation: All three syntaxes are equivalent and select every attribute of the context node. Question 46. In XSLT, which element is used to define a reusable piece of stylesheet that can be called with parameters? A) <xsl:template> B) <xsl:function> (XSLT 2.0+) C) <xsl:call-template> D) Both B and C (B defines, C invokes) Answer: D Explanation: <xsl:function> defines a callable function (XSLT 2.0+); <xsl:call-template> invokes a named template, which can also accept parameters. Question 47. Which of the following XSD facets would you use to restrict a string to exactly 5 characters? A) length="5" B) minLength="5" maxLength="5" C) pattern=".{5}" D) All of the above are valid Answer: D Explanation: Each option correctly enforces a 5‑character length constraint. Question 48. In XPath, what does the expression //*/@id return? A) All id attributes of the root element only
B) All id attributes of any element in the document C) All id attributes of child elements of the root D) An error because //*/ is invalid syntax Answer: B Explanation: // selects all descendant-or-self nodes; */ selects all element nodes; @id then selects their id attributes. Question 49. Which XML feature ensures that element and attribute names are case‑sensitive? A) XML namespaces B) XML’s inherent syntax rules C) The DTD declaration D) The XML declaration version attribute Answer: B Explanation: XML syntax mandates case sensitivity for all names, independent of namespaces or DTDs. Question 50. In an XSD, what does the attribute nillable="true" allow for an element? A) The element may be omitted entirely B) The element may appear with xsi:nil="true" to indicate a null value C) The element must contain at least one child element D) The element must be empty (no content) Answer: B Explanation: nillable="true" permits the element to be present with the xsi:nil attribute set to true, representing a null. Question 51. Which XPath function would you use to convert a node‑set to a string? A) string()
A) The element
Question 57. Which XSLT element is used to create a new element in the output with a name computed at run time? A) <xsl:element name="{expression}"/> B) <xsl:copy> C) <xsl:value-of> D) <xsl:attribute> Answer: A Explanation: xsl:element with a name attribute that contains an XPath expression (enclosed in curly braces) creates dynamic element names. Question 58. In XSD, what is the effect of setting block="extension restriction" on a complexType? A) Prevents other types from extending or restricting this type B) Allows only extensions but not restrictions C) Disables all derivations (both extension and restriction) for this type D) Has no effect; block applies only to simple types Answer: C Explanation: The block attribute lists derivation methods that are prohibited; specifying both blocks both extension and restriction. Question 59. Which XPath axis would you use to select the parent of the current node? A) ancestor:: B) preceding:: C) parent:: D) self:: Answer: C