Reputation: 106904
Continuing my XSD questions for today:
In an XSD document, is the following:
<element />
a valid construct? That is, it's an element which does not have a name, type, anything. Totally anonymous.
And if this is a valid XSD, what does that mean? How would such an element appear in the XML?
Upvotes: 1
Views: 296
Reputation: 43651
Depends on where it is placed.
In xs:appInfo
or xs:documentation
(and few other constructs) anything may be valid.
Next this element:
<element />
Does not specify the namespace. So it is either in a wrong namespace or there's a xmlns="http://www.w3.org/2001/XMLSchema"
somewhere in the context.
Assuming the latter this may be a global (topLevelElement
) or a local (localElement
) element definition.
It is invalid in both cases:
name
attribute.name
or a ref
attribute. I think that just according the schema of the schema it might be syntactically valid, but there are restrictions in the specification:2 If the item's parent is not , then all of the following must be true:
2.1 One of ref or name must be present, but not both.
Upvotes: 1
Reputation: 111491
@name
attribute must appear in a global XSD element declaration.See 3.3.2 XML Representation of Element Declaration Schema Components, including where it states (emphasis added):
Note that the above allows for two levels of defaulting for unspecified type definitions. An
<element>
with no referenced or included type definition will correspond to an element declaration which has the same type definition as the head of its substitution group if it identifies one, otherwise the ·ur-type definition·. This has the important consequence that the minimum valid element declaration, that is, one with only a name attribute and no contents, is also (nearly) the most general, validating any combination of text and element content and allowing any attributes, and providing for recursive validation where possible.
Consider using wildcards such as xs:any
if you wish to allow any element. Note, however, that you'll at least need to name a root element.
Upvotes: 1