Why is my XML failing validation?

  • I'm developing a web interface in Visual Studio (.NET Core) to allow a user to upload an Excel file, format the contents into XML and then insert it into a database (running on SQL Server 2008(R2)).  This is to replace a system that uses a PowerShell script that did the same job.

    I've had to manipulate the date values coming from the Excel spreadsheet (for example, "Oct 10, 2019") to make them compliant with XML. I've tried formatting them into

    2019-10-10

    2019-10-10+00:00

    2019-10-10Z  (This is the format used by the PowerShell script)

    "{0:s}" -f ([datetime]::Parse($obj_file_contents_from_json.reporteddate)) + 'Z')

    and they all throw an error:

    XML Validation: Invalid simple type value: '2019-10-10'

    XML Validation: Invalid simple type value: '2019-10-10+00:00'

    XML Validation: Invalid simple type value: '2019-10-10Z'

    This is an example of what the raw XML string looks like just before passing to the stored procedure.

    <DataType>date</DataType><Value>2019-10-10</Value>
    <DataType>date</DataType><Value>2019-10-10+00:00</Value>
    <DataType>date</DataType><Value>2019-10-10Z</Value>

    What am I doing wrong?  Why is at least one of these not valid (according to various StackOverflow and other articles, either the 'Z' or the '+00:00' suffix should suffice).

    Thanks

    Edward

    • This topic was modified 3 years, 11 months ago by  edwardwill. Reason: Missing parentheses
  • I have figured out the answer (I would have deleted the post but I can't see how to do that!)

    It needed to be in the format yyyy-MM-ddThh:mm:ssZ.  It now works.  All I need to do now is to figure out what I need to pass in if the date is missing!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply