LoadXML on IXMLDOMDocument2 with xsi:nil="true"

M

MattM

I'm trying to load an XML document that has the xsi:nil attribute via code
and can't get it to work under certain circumstances. This code works fine:

Dim myXDoc2 As XDocument =
myApp.XDocuments.NewFromSolutionWithData("c:\data.xml", "c:\form.xsn")

However this code fails:

Dim myApp As Application = New Microsoft.Office.Interop.InfoPath.Application
Dim xdoc As New XmlDocument
xdoc.Load("c:\data.xml")
Dim myXDoc As XDocument = myApp.XDocuments.NewFromSolution("c:\form.xsn")
Dim x As IXMLDOMDocument2 = myXDoc.CreateDOM()
x.loadXML(xdoc.OuterXml)
Dim myXDoc2 As XDocument =
myApp.XDocuments.NewFromSolutionWithData(x.documentElement, "c:\form.xsn")

The problem is the IXMLDOMDocument2 refuses to load the XML when the xsi:nil
attribute is in the document. I don't understand why this happens since it
should be the same process as the NewFromSolutionWithData method. It's also
confusing because the XML document can be loaded in InfoPath just fine. I
can't figure out why the IXMLDOMDocument2 has a problem with this attribute.

Reading directly from the file or using the XML data file path is not an
option. I need to read the XML file separate from the InfoPath objects, that
is why I load the document into an XmlDocument object or I load it into a
String via a StreamReader.

All I can figure out is either InfoPath strips this attribute when it loads
the XML or that a different object is used by the NewFromSolutionWithData
method.

Any ideas.
 
M

MattM

Thanks. I finally stumbled across that. Any explaination of why or what
drawbacks this can cause? My guess is that this is what InfoPath does itself
since it's InfoPath that puts the xsi:nil into the XML in the first place.

I also finally figured out that the DOMDocument50 object can be used to feed
the NewFromSolutionWithData method. The documentation for
NewFromSolutionWithData is not very clear as to what data types are
acceptable. I could have saved a lot of time if I had known this. I'm not
sure why this method requires you to also have the XSN name or if anything
else is acceptable.
 

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