After adding a sec. datasource a strange problem occurs

S

StefanO-nl

After I've added a secondary datasource (which is actually an xslt, but that's beside the point here), I can't open my form anymore, because InfoPath shows me an error about an invalid event handler. That event handler hasn't changed and after removing the secondary datasource, there are no errors, so I'm pretty sure it has something to do with this secondary datasource... But what could be the problem?
 
S

Steve van Dongen [MSFT]


He added it as a resource, not as a secondary datasource. I don't see
any possible reason that an XSLT could/would/should be used as a
secondary datasource. Perhaps you could explain what you are trying
to accomplish. The Data Interop SDK sample demonstrates transforming
data using XSLT resource files.

Regards,
Steve
 
M

Matthew Blain \(Serriform\)

That sounds odd. What event handler is InfoPath complaining about? I have a
template which has an XSLT and it works fine, though it's pre-SP1. (Yes, it
still opens after adding SP-1 features).

Steve, the reason you'd add it as a data connection instead of just a
resource is to use GetDOM.

--Matthew Blain
http://tips.serriform.com/

StefanO-nl said:
The fact my secondary datasource is an xslt-file, does matter, because of
the namespace declaration
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"...
 
S

Steve van Dongen [MSFT]

Steve, the reason you'd add it as a data connection instead of just a
resource is to use GetDOM.

But if all you need is the DOM you don't need all the overhead of a
data connection. As the Data Interop SDK sample shows you can load
XSLT files added as resources just fine.

objSalesSummaryXSLT = new ActiveXObject("MSXML2.DomDocument.5.0");
objSalesSummaryXSLT.async = false;
objSalesSummaryXSLT.load("SalesSummaryByYearTransform.xsl");

Regards,
Steve
 
M

Matthew Blain \(Serriform\)

Drifting off topic here, but what's the difference between a data connection
to an XML file which is a resource in a template, and creating your own
instance of the XML DOM loaded from a resource in the template? Other than
the caching being done in a different place? (The data interop example
caches the DOM, though I didn't look closely to see at what time.)
 
S

Steve van Dongen [MSFT]

Drifting off topic here,

Ha. You call this off-topic? This is nothing. ;)
but what's the difference between a data connection
to an XML file which is a resource in a template, and creating your own
instance of the XML DOM loaded from a resource in the template? Other than
the caching being done in a different place? (The data interop example
caches the DOM, though I didn't look closely to see at what time.)

I created a new form, saved it, and then tried adding 1 of the 2 XSL
files in the Data Interop sample and saved it again. The addition of
the XSL caused the addition of 9KB (2KB compressed) worth of XSD
files. If I add the second XSL file, I get another 9KB of XSD files.
Those 6 additional XSD files will have to be cached.

The manifest.xsf has details on the added XSD files themselves as well
as the secondary datasource. Also, because I have SP1, a bunch of
junk related to the XSL structure got added to the sampledata.xml
file.

Aside from file sizes, there are thing that happen at runtime like the
XSL being validated against the schema when it is loaded and (SP1)
determining whether to fire change events as the secondary datasource
is loaded.

Granted, the performance degradation probably won't amount to much and
the increased file size probably won't be noticed by anyone except
over a slow link, but it's still more than nothing.

Regards,
Steve
 
S

StefanO-nl

I'm trying to perform an xslt on my InfoPath-xml, but apparently I have no idea how to access an xslt when it's a resource file... Therefore I tried it by making the xslt a secondary datasource, because then I know I how to retrieve the xslt from the secondary datasource and perform the actual transformation:
// First load the InfoPath xml into an XmlDocument
XmlDocument infoPathDocument = new XmlDocument();
infoPathDocument.LoadXml(thisXDocument.DOM.xml);
// Then load the xslt (in the secondary datasource) into an XmlDocument
thisXDocument.DataObjects["myTransformer"].Query();
XmlDocument xsltDocument = new XmlDocument();
xsltDocument.LoadXml(thisXDocument.DataObjects["myTransformer"].DOM.xml);
// Load the xslt into the XslTransform-class
XslTransform xslt = new XslTransform();
xslt.Load(xsltDocument.CreateNavigator(), new XmlUrlResolver(), this.GetType().Assembly.Evidence);
// And finally perform the transformation and write the output to file:
using (FileStream fs = new FileStream(@"C:\temp\output.xml", FileMode.Create)) {
xslt.Transform(infoPathDocument.CreateNavigator(), null, fs, new XmlUrlResolver());
}
 
S

StefanO-nl

Matthew Blain (Serriform) said:
That sounds odd. What event handler is InfoPath complaining about?

Some OnClick-event of a button...
I have a
template which has an XSLT and it works fine, though it's pre-SP1. (Yes, it
still opens after adding SP-1 features).

Pre-SP1 means script. I also have XSLT working with script code, but I want
to use the real stuff and do it in C#...
Steve, the reason you'd add it as a data connection instead of just a
resource is to use GetDOM.

Right. And I thought that was easy, but now I'm getting all kinds of other
problems.

I think it has something to do with the fact the namespace(s) of the
secondary datasource are copied to the manifest.xsf...

StefanO-nl
stefano AT etx.nl
 
S

StefanO-nl

Solution for my problem:

// First create a "COM" DOM and load the xslt resource file into that DOM
IXMLDOMDocument domDocument = thisXDocument.CreateDOM();
domDocument.load("transform.xslt");

// Create an XmlDocument and load the xml of the DOM.
XmlDocument xsltDocument = new XmlDocument();
xsltDocument.LoadXml(domDocument.xml);

// Then load the xml of that DOM into a .Net XmlDocument
XmlDocument xsltDocument = new XmlDocument();
xsltDocument.LoadXml(domDocument.xml);

// Load the InfoPath xml into a .Net XmlDocument
XmlDocument infoPathDocument = new XmlDocument();
infoPathDocument.LoadXml(thisXDocument.DOM.xml);

// Load the xslt into the XslTransform-class
XslTransform xslt = new XslTransform();
xslt.Load(xsltDocument.CreateNavigator(), new XmlUrlResolver(),
this.GetType().Assembly.Evidence);

// And finally perform the transformation and write the output to file:
using (FileStream fs = new FileStream(@"C:\temp\output.xml",
FileMode.Create)) {
xslt.Transform(infoPathDocument.CreateNavigator(), null, fs, new
XmlUrlResolver());
}


But I still wonder why (in my case) InfoPath can't handle the xslt-file as a
secondary datasource and throws strange exceptions...
Just for the record: I didn't change anything else in my form or in the
xslt-file.
 
Top