2

XSD

<xs:element name="Notes" minOccurs="0" maxOccurs="unbounded">
  <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Note" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Subject" type="xs:string" minOccurs="0"/>
            <xs:element name="Note" type="xs:string" minOccurs="0"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Current Output XML when Subject and Note are empty:

<Notes>
   <Note/>
</Notes>

However when Subject and Note are empty, I don't want any output.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Philip
  • 73
  • 7
  • Well, a schema does not create any output at all, it is used to validate instance documents against its defined grammar. If you are using a tool or some data binding API to generate an instance document from a schema then you need to tell us the details of which tool you use, how you use it. – Martin Honnen Feb 04 '16 at 12:29

1 Answers1

0

Difference between XSD and XSLT

XSD is used for validation.

  • Input: XML document
  • Output: Validation results

An XSD specifies the constraints by which an XML document is valid. The output of validation is either success or failure, and with failure, there are usually diagnostic messages explaining the constraint violations. Your current output XML would be valid according to your XSD element declarations, as would just <Notes/>. However, an empty document would not be valid because it would not be well-formed.

XSLT is used for transformation.

  • Input: XML document*
  • Output: XML document*

An XSLT transformation specifies a mapping from input XML to output XML. It uses XPath to select parts of the input so that they can conditionally be included and arranged in the output. The language of your question suggests that you may wish to use XSLT, not XSD, to achieve your results. XSLT transforms input to output based upon user-provided templates, not the constraints given in an XSD.**

*Output can alternatively be text; input for XSLT 2.0 alternatively can also be text.

**XSLT 2.0 processors can be schema-aware but offer no automated mapping facilities.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240