Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3849

"elementFormDefault" should be "qualified"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      * Add an 'elementFormDefault="qualified"' attribute to this schema.
      * Set "elementFormDefault" to "qualified".
      Show
      * Add an 'elementFormDefault="qualified"' attribute to this schema. * Set "elementFormDefault" to "qualified".
    • Highlighting:
      • <xs:schema if no elementFormDefault attribute
      • elementFormDefault="unqualified" if attribute present
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Targeted languages:
      XML
    • Irrelevant for Languages:
      ABAP, C#, C, C++, Cobol, CSS, Flex, HTML, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, VB.Net, VB6
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      It can be tempting to set elementFormDefault to unqualified, because it allows XML document authors to remove a few prefixes in their files. However this is not a good practice for several reasons:

      • The unqualified form doesn't convey any functionality.
      • Most XML schemas are qualified, so defining a few unqualified schemas requires the author of an XML document to fully master both cases with no added value.
      • The unqualified form implies that in the XML document, all global elements from the schema must be qualified, and all local elements must be unqualified. So the author must be very cautious regarding the local vs. global nature of each element.
      • The unqualified form implies that in an XML document, the default namespace cannot be used. This stems from the fact that a document's default namespace qualifies all prefix-less elements, and an element cannot be both qualified and unqualified. For the XML document author, being prevented from using the default namespace is a real nuisance.
      • In some cases, the unqualified form degrades performance, by requiring the processing tool to look up the unqualified elements in the schema file.

      Noncompliant Code Example

      <xs:schema targetNamespace="http://www.codeSamples.com/fruit"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 version="1">                                 <!-- Noncompliant -->
      ...
      

      Compliant Solution

      <xs:schema targetNamespace="http://www.codeSamples.com/fruit"
                 xmlns:xs="http://www.w3.org/2001/XMLSchema"
                 elementFormDefault="qualified" version="1">
      ...
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: