To declare the version of XML, the correct syntax is

2015

To declare the version of XML, the correct syntax is

  1. A.

    <?xml version="1.0"?>

  2. B.

    <*xml version="1.0">

  3. C.

    <*xml version=="1.0">

  4. D.

    <*xml version="1.0"

Attempted by 148 students.

Show answer & explanation

Correct answer: A

An XML declaration is a special declaration that must appear as the very first line of an XML document. Its delimiters, <? and ?>, look like those of a processing instruction, but it is not one — a genuine processing instruction's target name can never be the reserved word "xml". The XML declaration exists solely to state metadata about the document itself (its XML version, and optionally its encoding and standalone status), not document content. Like any XML attribute, the version attribute is assigned using standard attribute syntax: name="value", with a single equals sign and a matching pair of quotes.

Checking the options against this rule, <?xml version="1.0"?> opens with the reserved <?xml marker, assigns the version attribute using a single = and matching double quotes, and closes with ?> — every requirement of a valid XML declaration is satisfied.

  • <*xml version="1.0"> replaces the reserved opening <? with an asterisk (*) and closes with a plain '>' instead of '?>', so it is not a valid XML declaration at all.

  • <*xml version=="1.0"> carries the same invalid asterisk opening, and additionally uses a double equals sign (==) — a comparison operator, not an attribute-assignment operator — to assign the version.

  • <*xml version="1.0" carries the same invalid opening character and is never closed — it has no ?> or even a plain '>' to end the tag.

Since only one option forms a complete, correctly delimited XML declaration, <?xml version="1.0"?> is the correct syntax for declaring the XML version.

Explore the full course: Isro

Loading lesson…