rspec/rules/S3849/xml/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

52 lines
2.1 KiB
Plaintext

== Why is this an issue?
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
[source,xml]
----
<xs:schema targetNamespace="http://www.codeSamples.com/fruit"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1"> <!-- Noncompliant -->
...
----
=== Compliant solution
[source,xml]
----
<xs:schema targetNamespace="http://www.codeSamples.com/fruit"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" version="1">
...
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Add an 'elementFormDefault="qualified"' attribute to this schema.
* Set "elementFormDefault" to "qualified".
=== Highlighting
* ``++<xs:schema++`` if no ``++elementFormDefault++`` attribute
* ``++elementFormDefault="unqualified"++`` if attribute present
endif::env-github,rspecator-view[]