AnsweredAssumed Answered

No XML tags instead of attribute xsi:nil='true'

Question asked by trgerhardt on Jul 25, 2007
Latest reply on Jul 26, 2007 by arielb
How do you code an XSD so that the tags just don't show up if there is no content instead of having xsi:nil="true"?

XSD File:
<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <xs:include schemaLocation="/includes/schemas/Public Images.xsd"/>

  <xs:element name="object" type="objectType" />

  <xs:complexType name="objectType">
    <xs:sequence>
      <xs:element name="name" type="xs:normalizedString" />
      <xs:element name="image" type="imageType" minOccurs="0" />
      <xs:element name="post" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:normalizedString" />
            <xs:element name="url" type="xs:normalizedString" minOccurs="0" />
            <xs:element name="date" type="xs:date" minOccurs="0" />
            <xs:element name="image" type="imageType" minOccurs="0" />
            <xs:element name="body" type="xs:string" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence> 
  </xs:complexType>
   
</xs:schema>

XML Printed:
<object>
  <name>Test</name>
    <image xsi:nil="true">
      <title xsi:nil="true"/>
      <filename xsi:nil="true"/>
    </image>
    <post>
      <title>test</title>
      <url xsi:nil="true"/>
      <date xsi:nil="true"/>
      <image xsi:nil="true">
        <title xsi:nil="true"/>
        <filename xsi:nil="true"/>
      </image>
    <body>test</body>
  </post>
</object>

Outcomes