What is an empty element in XSD?
A
An element that contains both attributes and text B
An element that has no content or child elements C
An element that repeats multiple times D
An element that only contains child elements
Analysis & Theory
Empty elements are those that contain neither text nor child elements — they are self-closing or end with no content.
How do you define an element as empty in XSD?
A
By using `<xs:element empty="true"/>` B
By setting `minOccurs='0'` and `maxOccurs='0'` C
By using `<xs:complexType><xs:sequence/></xs:complexType>` D
By assigning the type `xs:empty`
Analysis & Theory
To define an empty element, use a complexType with an empty `<xs:sequence>` — meaning no child elements.
Which of the following defines a valid empty element named 'spacer'?
A
<xs:element name="spacer" type="xs:empty"/> B
<xs:element name="spacer"><xs:complexType><xs:sequence/></xs:complexType></xs:element> C
<xs:element name="spacer"><xs:simpleType/></xs:element> D
<xs:element name="spacer" empty="true"/>
Analysis & Theory
This structure uses a complexType with an empty sequence, which defines the element as empty.
What will happen if an XML element declared as empty contains text or child elements?
A
It will be ignored by the parser B
It will be treated as a comment C
It will cause a validation error D
It will be automatically removed
Analysis & Theory
If an empty element contains any content, validation will fail according to the schema.
Which of the following XML elements would be valid for this XSD declaration?
```xml
<xs:element name="break">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
```
A
<break>pause</break> B
<break><line/></break> C
<break/> D
<break attr="value"/>
Analysis & Theory
`<break/>` is valid because it's empty. The declaration allows no text or child elements.
Can an empty element in XSD have attributes?
A
No, empty elements must be completely empty B
Yes, using `<xs:attribute>` inside the complexType C
Only if the element has a simpleType D
Only in DTD, not XSD
Analysis & Theory
You can define an empty element that still has attributes by including `<xs:attribute>` inside its `<xs:complexType>`.