Conversion from JScript to C# - Infopath2007 - urgent please help

D

Dotnetdev

Hi Gurus,



I need to convert this code from JScript to C#. I have a drop down list. It
is binded to two datasources. One is with webservices which provide stream of
data(unformatted data) and another with an xml file which formats this data.
The code was written in JScript before and now the client wants to convert it
to C#. Here is the JScript code(written in onload event).



function XDocument:: OnLoad(eventObj)
{
var objDataObject;
objDataObject =
XDocument.DataObjects("A").DOM.loadXML(XDOcument.DataObjects("B").DOM.XML);
}

where A is dataconnection to xml file and B is dataconnection to webservice.
Please help.



Thanks in advance
 
R

RP

Do the following on FormEvents_Loading event:

XPathNavigator xpnA = DataSources["A"].CreateNavigator();
XPathNavigator xpnB = DataSources["B"].CreateNavigator();

xpnA.InnerXml = xpnB.InnerXml;

Create FormEvents_Loading handler from Menu -> Tools -> Programming ->
Loading Event

Hth,
RP
 
D

Dotnetdev

Hi RP,

I tried that code. I got this error.

System.Xml.XmlException
Unexpected XML declaration. The XML declaration must be the first node in
the document, and no white space characters are allowed to appear before it.
Line 1, position 9.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParsePI(BufferBuilder piInDtdStringBuilder)
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader,
XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.Xsl.Runtime.XmlQueryContext.ConstructDocument(Object
dataSource, String uriRelative, Uri uriResolved)
at System.Xml.Xsl.Runtime.XmlQueryContext..ctor(XmlQueryRuntime runtime,
Object defaultDataSource, XmlResolver dataSources, XsltArgumentList argList,
WhitespaceRuleLookup wsRules)
at System.Xml.Xsl.Runtime.XmlQueryRuntime..ctor(XmlILCommand cmd, Object
defaultDataSource, XmlResolver dataSources, XsltArgumentList argList,
XmlSequenceWriter seqWrt)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter
results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument,
XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer,
Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(XmlReader contextDocument,
XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(XmlReader input,
XsltArgumentList arguments, TextWriter results)
at Microsoft.Office.InfoPath.MsxmlWriter.Close()
at System.Xml.XmlWellFormedWriter.Close()
at System.Xml.XPath.XPathNavigator.AppendChild(XmlReader newChild)
at System.Xml.XPath.XPathNavigator.AppendChild(String newChild)
at Microsoft.Office.InfoPath.MsxmlNavigator.set_InnerXml(String value)
at ListofNames.FormCode.FormEvents_Loading(Object sender,
LoadingEventArgs e)
at
Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent
pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

Please help. Thanks
 
R

RP

It appears that we have to select the root node and have to transfer
XML.

Use the following steps in FormEvents_Loading:

XPathNavigator xpnA = DataSources["A"].CreateNavigator();
XPathNavigator xpnB = DataSources["B"].CreateNavigator();

XPathNavigator xpnARoot = xpnA.SelectSingleNode("/my:RootNode",
this.NamespaceManager);
XPathNavigator xpnBRoot = xpnB.SelectSingleNode("/my:RootNode",
this.NamespaceManager);

xpnARoot.InnerXml = xpnBRoot.InnerXml;

Also, make sure A and B follows the same schema.

Hth,
RP
 
D

Dotnetdev

Hi RP,

Still I'm having an error. The error is this - System.NullReferenceException
Object reference not set to an instance of an object.
at ListofNames.FormCode.FormEvents_Loading(Object sender,
LoadingEventArgs e)
at
Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent
pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

Please help

Thank you very much
 

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