XML Validation Failure Due To Invincible White Space

After spending 3 hours of my life trying to resolve the following error message:

The element cannot contain white space. Content model is empty

I decided to share my solution in hope that this will help somebody else. The xml file that was failing validation is:

<?xml version="1.0" encoding="utf-8"?>
<ComponentSet Default="Create Data Set">
  <Procedures>
    <Procedure Name="Create Data Set">
      <MainFlow>
        <CreateDataSetVersion Name="run create data set version task" 
                              Description="this the description"
                              CollectionId="collection" 
                              DataProviderId="dataprovider"
                              DataSetDescription="datasetDescription"
                              DataSetName="datasetName" 
                              DataSetSchemaCode="schemaCode"
                              DataSetVersionCode="datasetCode">
        </CreateDataSetVersion>
      </MainFlow>
    </Procedure>
  </Procedures>
</ComponentSet>

And the xsd part responsible for the validation is listed below:

<xs:element name="CreateDataSetVersion">
  <xs:complexType>
    <xs:attribute name="Name" type="dcftstring" use="required" />
    <xs:attribute name="Description" type="dcftstring" use="required" />
    <xs:attribute name="DataSetName" type="dcftstring" use="required" />
    <xs:attribute name="DataSetVersionCode" type="dcftstring" use="required" />
    <xs:attribute name="DataSetSchemaCode" type="dcftstring" use="required" />
    <xs:attribute name="CollectionId" type="dcftstring" use="required" />
    <xs:attribute name="DataProviderId" type="dcftstring" use="required" />
    <xs:attribute name="DataSetDescription" type="dcftstring" use="required" />
    <xs:attribute name="SchemaScripts" type="xs:string" use="optional" />
    <xs:attribute name="Condition" type="xs:string" use="optional" />
    <xs:attribute name="SendErrorMessage" type="xs:string" use="optional" />
  </xs:complexType>
</xs:element></pre>

So here is the basic check list I went through to resolve the issue:

  • Check for missing quotes
  • Check for unclosed tags
  • Check for typos
  • Remove the spaces from from the xml attribute values
  • Copy paste the xml to notepad to remove hidden/erroneous characters and paste back to the xml file
  • Turn on the Show Spaces feature in Visual Studio (Edit -> Advanced ->; View White Space)

And still no joy. The error message kept on popping up no matter what I tried. Then I decided to reformat my xml code letting Visual Studio to decide on the layout! (Ctrl + A, Ctrl + E, Ctrl + F). This formatted the xml file as shown below:

<?xml version="1.0" encoding="utf-8"?>
<ComponentSet Default="Create Data Set">
  <Procedures>
    <Procedure Name="Create Data Set">
      <MainFlow>
        <CreateDataSetVersion Name="run create data set version task" Description="this the description"
                              CollectionId="collection" DataProviderId="dataprovider" DataSetDescription="datasetDescription"
                              DataSetName="datasetName" DataSetSchemaCode="schemaCode" DataSetVersionCode="datasetCode"></CreateDataSetVersion>
      </MainFlow>
    </Procedure>
  </Procedures>
</ComponentSet>

The solution:

Although the auto-format didn't do much other than compress 6 lines of code into 3 inside the failing xml element, the problem went away so there must have been some hidden character somewhere on this page causing the exception.

Happy coding...


  • Share this post on