Pick out the invalid element naming rule for an XML element from the following…

2017

Pick out the invalid element naming rule for an XML element from the following rules :

Answer: A. Names can start with a number or punctuation character.Concept: Under the W3C XML 1.0 specification, an element name is drawn from a defined character set. By the standard naming convention used in practice, the…

  1. A.

    Names can start with a number or punctuation character.

  2. B.

    Names can contain letters, numbers, hyphens, underscores and periods.

  3. C.

    Names cannot contain spaces

  4. D.

    Names must not start with the letters XML in any case combination.

Attempted by 378 students.

Show answer & explanation

Correct answer: A

Concept: Under the W3C XML 1.0 specification, an element name is drawn from a defined character set. By the standard naming convention used in practice, the first character of a name must be a letter or an underscore — the colon is a special exception reserved for namespace prefixes, not a general-purpose punctuation start, so ordinary digits and punctuation marks are excluded from the first position. Only after that first character may a name include digits, hyphens, and periods. A name can never contain whitespace, and the specification separately reserves the case-insensitive sequence "xml" (xml, XML, Xml, and so on) for XML's own use, so document authors must not begin a name with it.

Application: Checking each of the four statements against that convention: "Names can start with a number or punctuation character" contradicts the naming rule directly — outside the special namespace-reserved colon, a digit or punctuation mark is never a valid first character of an XML name, so this statement is false and is the invalid rule the question is asking to identify.

  • "Names can contain letters, numbers, hyphens, underscores and periods" — true, since these characters are exactly the ones permitted after the first character of a name.

  • "Names cannot contain spaces" — true, since an XML name must be a single, unbroken token.

  • "Names must not start with the letters XML in any case combination" — true, since the specification reserves the sequence "xml" for its own use and forbids authors from starting a name with it.

Cross-check: The formal grammar NameStartChar ::= ":" | [A-Za-z] | "_" | ... permits only the colon as a namespace-reserved exception, while excluding digits and ordinary punctuation from the first-character set — confirming the flagged statement is the only false one among the four under the standard naming convention; the other three each describe a real, practically-enforced XML naming constraint.

Result: The statement "Names can start with a number or punctuation character" is the invalid XML element naming rule among the four presented.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Hpsc Pgt Computer Science

Loading lesson…