March 9, 2010

InfoPath: Element is not defined in the DTD/Schema

I had imported data from an Excel document to SQL Server and was performing queries against this data from an InfoPath Form.

On some records the query worked fine but in others received this error:

The query method on the Document object failed.
InfoPath cannot run the specified query. The attribute '{http://www.w3.org/XML/1998/namespace}space' on the element 'DocumentTitle' is not defined in the DTD/Schema.

Looking at the data, I could not find special characters or anything that would cause this error.
I opened the WebService project and placed a breakpoint in the code right after the DataSet was being filled. In the immediate window I typed

? ds.GetXml()









Upon inspecting the XML being sent to the form, I noticed some tags contained

<DocumentTitle xml:space="retain"> <\DocumentTitle>


To make a long story short, you can solve the problem by running the following query:

UPDATE [Table_Name] SET [FieldName]= ''
WHERE [FieldName] = '' ;


Hope this helps!

- Radamés