C
Charl
Hello,
I've made an Infopath form looking a lot to the DataInterop example in the
SDK. In my form I've a secundary datasource (webservice) which I would like
to make available offline, so I made a method CacheAuxiliaryDOMs() like the
DataInterop example. When executing the following line of code:
objOfflineDataNode.parentNode.replaceChild(objNewOfflineDataNode,
objOfflineDataNode);
I get the following error:
Element
'{http://schemas.microsoft.com/office/infopath/2003/dataFormSolution}myFields'
is unexpected according to content model of parent element
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06}users'. line: 160
As far as I can over see the problem, I think the problem is an
casting/converting problem. I know not so much about namespaces, but it seems
that my main document source has an other namespace then my secundary
(webservice) datasource. And when I add the secundary xml data tree to my
main data tree (so that the data is saved for offline use) the exception
rises.
The question is, how to fix this error so the secundary data is copied into
the main xml tree (how to cast the xml data from one namespace to another?)?
(Below I've included the whole function CacheAuxiliaryDOMs() and the files
script.js and manifest.xsd and getMedewerkers.xsd if it's needed to help me)
Thanks,
Charl
The function where this occurs is:
function CacheAuxiliaryDOMs()
{
var objOfflineDataNode = null;
var objNewOfflineDataNode = null;
var objNode = null;
// Get the current SalesSummaryData node.
objOfflineDataNode =
XDocument.DOM.selectSingleNode("/my:mijnVelden/myfflinedata");
// Build up a XML fragment containing curent contents of the auxiliary DOMs.
// The fragment consists of the results of several XSLT transforms applied
// to the XML downloaded from the database.
objNewOfflineDataNode = objOfflineDataNode.cloneNode(false);
// Build up a XML fragment containing current contents of the auxiliary DOMs.
objNode = XDocument.DOM.createNode(1, "users",
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06")
objNode.appendChild(XDocument.GetDOM("getMedewerkers").documentElement.cloneNode(true));
objNewOfflineDataNode.appendChild(objNode);
// Insert the new offline data to the DOM.
objOfflineDataNode.parentNode.replaceChild(objNewOfflineDataNode,
objOfflineDataNode);
}
I've made an Infopath form looking a lot to the DataInterop example in the
SDK. In my form I've a secundary datasource (webservice) which I would like
to make available offline, so I made a method CacheAuxiliaryDOMs() like the
DataInterop example. When executing the following line of code:
objOfflineDataNode.parentNode.replaceChild(objNewOfflineDataNode,
objOfflineDataNode);
I get the following error:
Element
'{http://schemas.microsoft.com/office/infopath/2003/dataFormSolution}myFields'
is unexpected according to content model of parent element
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06}users'. line: 160
As far as I can over see the problem, I think the problem is an
casting/converting problem. I know not so much about namespaces, but it seems
that my main document source has an other namespace then my secundary
(webservice) datasource. And when I add the secundary xml data tree to my
main data tree (so that the data is saved for offline use) the exception
rises.
The question is, how to fix this error so the secundary data is copied into
the main xml tree (how to cast the xml data from one namespace to another?)?
(Below I've included the whole function CacheAuxiliaryDOMs() and the files
script.js and manifest.xsd and getMedewerkers.xsd if it's needed to help me)
Thanks,
Charl
The function where this occurs is:
function CacheAuxiliaryDOMs()
{
var objOfflineDataNode = null;
var objNewOfflineDataNode = null;
var objNode = null;
// Get the current SalesSummaryData node.
objOfflineDataNode =
XDocument.DOM.selectSingleNode("/my:mijnVelden/myfflinedata");
// Build up a XML fragment containing curent contents of the auxiliary DOMs.
// The fragment consists of the results of several XSLT transforms applied
// to the XML downloaded from the database.
objNewOfflineDataNode = objOfflineDataNode.cloneNode(false);
// Build up a XML fragment containing current contents of the auxiliary DOMs.
objNode = XDocument.DOM.createNode(1, "users",
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06")
objNode.appendChild(XDocument.GetDOM("getMedewerkers").documentElement.cloneNode(true));
objNewOfflineDataNode.appendChild(objNode);
// Insert the new offline data to the DOM.
objOfflineDataNode.parentNode.replaceChild(objNewOfflineDataNode,
objOfflineDataNode);
}
Code:
/*
* Dit bestand bevat functies voor gegevensvalidatie en gebeurtenissen op
formulierniveau.
* Omdat in het bestand met de formulierdefinitie (.XSF) naar de functies
wordt verwezen,
* is het raadzaam geen wijzigingen aan te brengen in de naam van de functie
* of de naam van argumenten en het aantal argumenten.
*
*/
// De volgende regel wordt gemaakt door Microsoft Office InfoPath om de
voorvoegsels te definiëren
// voor alle bekende naamruimten in het XML-hoofdgegevensbestand.
// Wijzigingen in de formulierbestanden die buiten InfoPath
// worden aangebracht, worden niet automatisch bijgewerkt.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06"');
//</namespacesDefinition>
//=======
// De volgende functie-handler wordt gemaakt door Microsoft Office InfoPath.
// Breng geen wijzigingen aan in de naam van de functie en argumenten of in
het aantal argumenten.
//=======
function cmdGetAgenda::OnClick(eventObj)
{
updateAgenda();
}
function updateAgenda()
{
try
{
var sUser =
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:cboUser").text;
var sDatum =
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:txtDatum").text;
//Get a reference to the SDS bound to the Web Service.
var theDataObject = XDocument.DataObjects.Item("getAgendaDag");
//Set the SelectionNamespaces so that you can find the correct field.
// Note: If the Web service was created with Visual Studio 2003, the
xmlns:s0 namespace is:
// http://tempuri.org/PopulateCities/Service1
theDataObject.DOM.setProperty("SelectionNamespaces",
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' +
'xmlns:s0="http://tempuri.org/"');
var qDatum = theDataObject.DOM.selectSingleNode(
"/dfs:myFields/dfs:queryFields/s0:getAgendaDag/s0:datum" );
qDatum.text = sDatum;
var qGebruiker = theDataObject.DOM.selectSingleNode(
"/dfs:myFields/dfs:queryFields/s0:getAgendaDag/s0:gebruiker" );
qGebruiker.text = sUser;
theDataObject.Query();
}
catch(ex)
{
}
//XDocument.View.ForceUpdate();
}
//=======
// De volgende functie-handler wordt gemaakt door Microsoft Office InfoPath.
// Breng geen wijzigingen aan in de naam van de functie en argumenten of in
het aantal argumenten.
//=======
function XDocument::OnLoad(eventObj)
{
try
{
// Attempt to load the auxilliary DOMs from the SQL Server.
XDocument.UI.Alert(LoadAuxiliaryDOMs());
// Open the solution at the Query View if the user is currently online and
has not
// queried for any orders yet and, otherwise, skip to the Orders view.
Also,
// if ther user is offline load the auxiliary DOMs from the cached data.
/*if (gblnOnline)
{
if (XDocument.DOM.selectSingleNode("/my:mijnVelden/my:cboUser").text != "")
{
XDocument.ViewInfos("Query").IsDefault = true;
}
else
{
XDocument.ViewInfos("Orders").IsDefault = true;
}
}
else
{
LoadAuxiliaryDOMs(true);
XDocument.ViewInfos("Orders").IsDefault = true;
}*/
}
catch (ex)
{
XDocument.UI.Alert(FormatErrorMessage(ex));
eventObj.ReturnStatus = false;
}
}
function LoadAuxiliaryDOMs(blnLoadFromCache)
{
if (XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text)
{
try
{
XDocument.DataObjects.Item("getMedewerkers").Query();
}
catch (ex)
{
if (ex.number == -2147209164){
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text = false;
}
else
throw ex;
}
}
else
{
var domUsers = XDocument.GetDOM("getMedewerkers");
var objNode = null;
objNode =
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:offlinedata/my:users");
if (objNode && objNode.firstChild)
domUsers.insertBefore(objNode.firstChild.cloneNode(true),
domUsers.firstChild);
else
throw new Error(0, "Cannot load document while offline. There is no
cached employee data.");
}
return XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text;
}
/*--------------------------------------------------------------
CacheAuxiliaryDOMs
Creates/replaces the /dfs:myFields/dfs:OfflineData node in the primary DOM
with a
fragment containing copies of the auxiliary DOMs.
ARGUMENTS:
None
RETURNS:
None
---------------------------------------------------------------*/
function CacheAuxiliaryDOMs()
{
var objOfflineDataNode = null;
var objNewOfflineDataNode = null;
var objNode = null;
// Get the current SalesSummaryData node.
objOfflineDataNode =
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:offlinedata");
// Build up a XML fragment containing curent contents of the auxiliary DOMs.
// The fragment consists of the results of several XSLT transforms applied
// to the XML downloaded from the database.
objNewOfflineDataNode = objOfflineDataNode.cloneNode(false);
// Build up a XML fragment containing current contents of the auxiliary DOMs.
objNode = XDocument.DOM.createNode(1, "users",
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06");
objNode.appendChild(XDocument.GetDOM("getMedewerkers").documentElement.cloneNode(true));
objNewOfflineDataNode.appendChild(objNode);
// Insert the new offline data to the DOM.
objOfflineDataNode.parentNode.replaceChild(objNewOfflineDataNode,
objOfflineDataNode);
}
//=======
// De volgende functie-handler wordt gemaakt door Microsoft Office InfoPath.
// Breng geen wijzigingen aan in de naam van de functie en argumenten of in
het aantal argumenten.
//=======
function btnOnlineOffline::OnClick(eventObj)
{
if (!XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text)
{
// online gaan
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text = true;
LoadAuxiliaryDOMs();
}
else
{
// offline gaan
XDocument.DOM.selectSingleNode("/my:mijnVelden/my:online").text = false;
CacheAuxiliaryDOMs();
}
}
[/code=script.js]
[code=manifest.xsd]
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema
targetNamespace="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06"
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
xmlns:s0="http://tempuri.org/"
xmlns:_xdns0="http://schemas.microsoft.com/office/infopath/2003/changeTracking"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns2="http://schemas.xmlsoap.org/wsdl/"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-08-12T14:50:06"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="mijnVelden">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="my:cboUser" minOccurs="0"/>
<xsd:element ref="my:txtDatum" minOccurs="0"/>
<xsd:element ref="my:veld3" minOccurs="0"/>
<xsd:element ref="my:cboAgenda" minOccurs="0"/>
<xsd:element ref="my:offlinedata" minOccurs="0"/>
<xsd:element ref="my:online" minOccurs="0"/>
</xsd:sequence>
<xsd:anyAttribute processContents="lax"
namespace="http://www.w3.org/XML/1998/namespace"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="cboUser" type="xsd:string"/>
<xsd:element name="txtDatum" nillable="true" type="xsd:date"/>
<xsd:element name="veld3" type="xsd:string"/>
<xsd:element name="cboAgenda" type="xsd:string"/>
<xsd:element name="offlinedata">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="my:users" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="users">
<xsd:complexType>
<xsd:sequence/>
</xsd:complexType>
</xsd:element>
<xsd:element name="online" nillable="true" type="xsd:boolean"/>
</xsd:schema>
[/code=manifest.xsd]
[code=getMedewerkers.xsd]
<?xml version="1.0"?>
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:s0="http://tempuri.org/">
<xsd:import namespace="http://tempuri.org/"
schemaLocation="getMedewerkers1.xsd"></xsd:import>
<xsd:element name="myFields">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="queryFields">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="s0:getMedewerkers"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="dataFields">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="s0:getMedewerkersResponse"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:any namespace="##other" processContents="lax" minOccurs="0"
maxOccurs="unbounded"></xsd:any>
</xsd:sequence>
<xsd:anyAttribute namespace="##other"
processContents="lax"></xsd:anyAttribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
[/code=getMedewerkers.xsd]