Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / February 2005

Tip: Looking for answers? Try searching our database.

LoadXML on IXMLDOMDocument2 with xsi:nil="true"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MattM - 28 Feb 2005 15:31 GMT
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.
Greg Collins [InfoPath MVP] - 28 Feb 2005 19:14 GMT
When loading XML with  xsi:nil, you need to set validateOnParse to false.

Signature

Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com

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.
MattM - 28 Feb 2005 22:37 GMT
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.

> When loading XML with  xsi:nil, you need to set validateOnParse to false.
>
[quoted text clipped - 31 lines]
>
> Any ideas.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.