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.
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.