Error reading InfoPath form into XmlDataDocument

E

Erik Reiter

I have an xml document that was created with infopath and I am trying to read
it with the following lines of code:

XmlDataDocument doc = new XmlDataDocument();
doc.Load(fileName);
return doc.DataSet;

or

DataSet SnippetLibraryDataSet = new DataSet();
SnippetLibraryDataSet.ReadXml(fileName, XmlReadMode.InferSchema);
return SnippetLibraryDataSet;

My goal it to get to a couple of the tables in the file.

I get the following error:

System.ArgumentException: The same table (font) cannot be the child table in
two nested relations.
at System.Data.DataRelation.CheckNestedRelations()
at System.Data.DataRelation.set_Nested(Boolean value)
at System.Data.XmlDataLoader.InferSchema(XmlElement tree, Hashtable
tableAtoms, DataTable table)
at System.Data.XmlDataLoader.InferSchema(XmlElement tree, Hashtable
tableAtoms, DataTable table)
at System.Data.XmlDataLoader.InferSchema(XmlElement tree, Hashtable
tableAtoms, DataTable table)
at System.Data.XmlDataLoader.InferSchema(XmlDocument xdoc, String[]
excludedNamespaces)
at System.Data.DataSet.ReadXml(XmlReader reader, XmlReadMode mode,
Boolean denyResolving)
at System.Data.DataSet.ReadXml(String fileName, XmlReadMode mode)

I also get a similar error with div instead of font.

Thanks,
Erik
 
S

S.Y.M. Wong-A-Ton

Did the XML for your InfoPath form contained rich text box fields by any
chance? If it did, you may want to remove them and see whether it helps or
use IgnoreSchema instead of InferSchema.
 
E

Erik Reiter

Yes I am useing multiple rich text boxs. I only get the error if the user of
the Info path fills out multiple rich text boxs if they only fill out one
then all of the code listed below works.

Can I use another control in its place that will not use divs or fonts?

I tryed IgnorSchema but the dataset does not get loaded.

The current code I am using is:

DataSet myds = new DataSet();
myds.ReadXml(filename, XmlReadMode.InferSchema);

I also tryed using:

XmlDataDocument doc = new XmlDataDocument();
doc.DataSet.ReadXmlSchema(@"c:\temp\myxsd.xsd");
doc.Load(fileName);
return doc.DataSet;

The xsd does not have the div or fonts in it just the tables I need, this
worked on my development machine, but I got the following exception on the
testers machine:

System.Xml.Schema.XmlSchemaException: The 'http://www.w3.org/1999/xhtml:div'
element is not declared. An error occurred at file:///c:/temp/myxsd.xsd, (31,
22).
at System.Xml.Schema.Compiler.SendValidationEvent(XmlSchemaException e,
XmlSeverityType severity)
at System.Xml.Schema.Compiler.CompileElement(XmlSchemaElement xe)
at
System.Xml.Schema.Compiler.CompileParticleElements(XmlSchemaComplexType
complexType, XmlSchemaParticle particle)
at
System.Xml.Schema.Compiler.CompileParticleElements(XmlSchemaComplexType
complexType, XmlSchemaParticle particle)
at
System.Xml.Schema.Compiler.CompileCompexTypeElements(XmlSchemaComplexType
complexType)
at System.Xml.Schema.Compiler.CompileTo(SchemaInfo schemaInfo)
at System.Xml.Schema.XmlSchema.Compile(XmlSchemaCollection collection,
XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler
validationEventHandler, String targetNamespace, SchemaInfo schemaInfo,
Boolean compileContentModel, XmlResolver resolver)
at System.Xml.Schema.XmlSchema.Compile(ValidationEventHandler
validationEventHandler)
at System.Data.DataSet.ReadXSDSchema(XmlReader reader, Boolean
denyResolving)
at System.Data.DataSet.ReadXmlSchema(XmlReader reader, Boolean
denyResolving)
at System.Data.DataSet.ReadXmlSchema(String fileName)

Erik
 
S

S.Y.M. Wong-A-Ton

You can use a normal text box and enable "Paragraph breaks" to make it
multi-line. But you'll lose being able to use markup (bold, italic, color,
etc) with the text.

The div and font comes from the XHTML tags being used for the contents of
the rich text field. You won't see this defined in the XSD, since you cannot
predict what the user is going to type into the rich text box including the
markup used. So in InfoPath a rich text box is defined as an "any" element,
meaning that it can contain any element(s). You'll also see "lax" defined for
the processContents attribute. Since some XML parsers only support "strict"
or "skip" for processContents, which might be possible in your case and what
is causing the error, since there is no definition in the XSD for the
elements defined in the rich text box, you'll need to use "skip" instead of
"lax" for the parser not to trip over this. So try changing that in the XSD
before switching over to using text boxes, that is, if that is an option for
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top