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 / November 2004

Tip: Looking for answers? Try searching our database.

InfoPath Form Data, Datasets, and Namespace issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Budde - 27 Oct 2004 22:12 GMT
I am attempting to build the following but running into problems.  The plan is to have a user fill in a form and submit the form data to a webservice. The webservice will then serialize the xml string submitted into a dataset where it can then be saved more easily to the database.

I defined the dataset in a c# object and then converted the main datasource in the infopath form to this dataset's XSD.  The form works fine, however when I submit the data to my webservice, by business object responsible for deserializing the XML form data into my dataset is balking at the namespace prefixes inserted into the xml doc.  If I manually remove the namespace prefixes from all my elements the xml form data deserializes without a problem.  

Here is what I have for my datasource XSD

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="SamplingEvent" targetNamespace=http://www.foobar.net/schemas/foobar
elementFormDefault="qualified" attributeFormDefault="qualified" xmlns=http://www.foobar.net/schemas/foobar
xmlns:mstns="http://www.diadenver.net/schemas/es/SampleEvent" xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:my=http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-09-26T22-51-25
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xd=http://schemas.microsoft.com/office/infopath/2003
xmlns:ns2="http://www.foobar.net/schemas/foobar" xmlns:dfs=http://schemas.microsoft.com/office/infopath/2003/dataFormSolution
xmlns:s0="http://www.tempuri.org" xmlns:ns1=http://schemas.xmlsoap.org/wsdl/
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:http=http://schemas.xmlsoap.org/wsdl/http/
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<xs:element name="SamplingEvent" msdata:IsDataSet="true">
   <xs:complexType>
       <xs:sequence>
           <xs:element name="SampleEventType" minOccurs="0" type="xs:string" maxOccurs="1" />
           ....

InfoPath Form Data

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.53" productVersion="11.0.6357" PIVersion="1.0.0.0" href="file:///C:\Data\Revision\DIA\Dev\ES\InfoPath\SWSampleCollection\bin\Debug\SWSampleCollection.xsn" name="urn:schemas-microsoft-com:office:infopath:DIA-Stormwater-Sample-Collection-Form:http---www-foobar-net-schemas-foobar" language="en-us" ?><?mso-application progid="InfoPath.Document"?><ns2:SamplingEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:s0="http://tempuri.org/" 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:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns1="http://schemas.xmlsoap.org/wsdl/" xmlns:ns2="http://www.foobar.net/schemas/foobar" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-09-26T22-51-25" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
<ns2:SampleEventType>OTHER</ns2:SampleEventType>
....

Dataset Code

public void SubmitSampleCollection(string xmlSampleCollection)
{
   //Serialize the Xml Doc into a dataset to make it easier to work with.
   SamplingEvent dsSamplingEvent = new SamplingEvent();  
   StringReader sr = new StringReader(xmlSampleCollection);
   XmlSerializer Xmls = new XmlSerializer(typeof(SamplingEvent));
   dsSamplingEvent = (SamplingEvent)Xmls.Deserialize(sr);        <-- line of interest

}

It is the ns2: prefix that is screwing up my deserialization process.  If I manually edit the Form's XML data by removing the ns2: prefix then I am able to deserialize without a problem.

So...my questions are these

1) Am I able to write infopath's form data without namespaces (something tells me no)?

2) How can I deserialize the xml into a dataset given the xml I'm getting in the form?

TIA

-Jim
Matthew Blain \(Serriform\) - 28 Oct 2004 07:23 GMT
At a quick glance that looks OK. Why are you passing the XML as a string
instead of an XMLDocument?

Another thing to look at is to serialize your class: create an instance in
code, then serialize it, then look at the namespaces.

Perhaps the serialization class doesn't have the right namespace info?
xsd.exe /classes should generate it correctly.

There's an example of this in the upcoming book mentioned below.

--Matthew Blain
http://tips.serriform.com/
http://www.developingsolutionswithinfopath.com
I am attempting to build the following but running into problems.  The plan
is to have a user fill in a form and submit the form data to a webservice.
The webservice will then serialize the xml string submitted into a dataset
where it can then be saved more easily to the database.

I defined the dataset in a c# object and then converted the main datasource
in the infopath form to this dataset's XSD.  The form works fine, however
when I submit the data to my webservice, by business object responsible for
deserializing the XML form data into my dataset is balking at the namespace
prefixes inserted into the xml doc.  If I manually remove the namespace
prefixes from all my elements the xml form data deserializes without a
problem.

Here is what I have for my datasource XSD

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="SamplingEvent"
targetNamespace=http://www.foobar.net/schemas/foobar
elementFormDefault="qualified" attributeFormDefault="qualified"
xmlns=http://www.foobar.net/schemas/foobar
xmlns:mstns="http://www.diadenver.net/schemas/es/SampleEvent"
xmlns:xs=http://www.w3.org/2001/XMLSchema
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:my=http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-09-26T
22-51-25
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xd=http://schemas.microsoft.com/office/infopath/2003
xmlns:ns2="http://www.foobar.net/schemas/foobar"
xmlns:dfs=http://schemas.microsoft.com/office/infopath/2003/dataFormSolution
xmlns:s0="http://www.tempuri.org" xmlns:ns1=http://schemas.xmlsoap.org/wsdl/
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:http=http://schemas.xmlsoap.org/wsdl/http/
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
<xs:element name="SamplingEvent" msdata:IsDataSet="true">
   <xs:complexType>
       <xs:sequence>
           <xs:element name="SampleEventType" minOccurs="0"
type="xs:string" maxOccurs="1" />
           ....

InfoPath Form Data
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution
solutionVersion="1.0.0.53" productVersion="11.0.6357" PIVersion="1.0.0.0"
href="file:///C:\Data\Revision\DIA\Dev\ES\InfoPath\SWSampleCollection\bin\De
bug\SWSampleCollection.xsn"
name="urn:schemas-microsoft-com:office:infopath:DIA-Stormwater-Sample-Collec
tion-Form:http---www-foobar-net-schemas-foobar" language="en-us"
?><?mso-application progid="InfoPath.Document"?><ns2:SamplingEvent
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolutio
n" xmlns:s0="http://tempuri.org/"
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:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns1="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns2="http://www.foobar.net/schemas/foobar"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-09-26
T22-51-25" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
<ns2:SampleEventType>OTHER</ns2:SampleEventType>
....
Dataset Code
public void SubmitSampleCollection(string xmlSampleCollection)
{
   //Serialize the Xml Doc into a dataset to make it easier to work with.
   SamplingEvent dsSamplingEvent = new SamplingEvent();
   StringReader sr = new StringReader(xmlSampleCollection);
   XmlSerializer Xmls = new XmlSerializer(typeof(SamplingEvent));
   dsSamplingEvent = (SamplingEvent)Xmls.Deserialize(sr);        <-- line
of interest
}
It is the ns2: prefix that is screwing up my deserialization process.  If I
manually edit the Form's XML data by removing the ns2: prefix then I am able
to deserialize without a problem.
So...my questions are these
1) Am I able to write infopath's form data without namespaces (something
tells me no)?
2) How can I deserialize the xml into a dataset given the xml I'm getting in
the form?
TIA
-Jim
Jim Budde - 05 Nov 2004 02:58 GMT
A refresher on the basics of my design.  I have a dotnet class that has Biz
Logic in it, in addition to a dataset class.  My InfoPath form is using the
XSD from this dataset as its main datasource.  I now have my form laid out
appropriately and able to submit my form data to a webservice, which
subsequently call my biz object to deserialize the xml doc into the dataset
where I then save the data to a DB.  In order to get the xmlDoc to
deserialize properly and to access the data I've had to do the following:

1) First, switching the webservice to accept an XMLDom Doc from a string
helped.
2) I *had* to strip any namespace prefixes out of the  xml data InfoPath
passes in.  Majorly ugly i know, but it was the only way I could figure out
how to get it to deserialize.
3) Make sure all elements in my XSD were string types (I distinctly remember
needing to do the same on a prior BizTalk 2002 project), otherwise
non-string elements don't get deserialized into the dataset.  The
deserialiazation occurs without errors, but accessing any column of data in
the dataset that is a non-string type will return a NULL value. Looking at
the column info in QuickWatch displays the following "error: an exception of
type: {System.Data.StrongTypingException} occurred"

The problem I have now is that validating and formatting the data in the
InfoPath form requires the elements be strongly typed which subsequently
breaks my dataset deserialization and business logic.  The only lame and
error-prone work-around I've come up with is to have two datasets, one
strongly typed to use within InfoPath, and a second one that I can use
within my code that operates with just strings.  I'm not even sure this
would work as I haven't implemented it yet.  Does anyone else have some
insights?

Thanks in advance!

-Jim

p.s. I have the latest SP applied for the dotnet framework. SP2 for dot net
1.1 (I believe that's the right one).

"Matthew Blain (Serriform)" <matthewblain@nospam.serriform.com> wrote in
message news:uMFG5bLvEHA.3376@TK2MSFTNGP12.phx.gbl...
> At a quick glance that looks OK. Why are you passing the XML as a string
> instead of an XMLDocument?
[quoted text clipped - 103 lines]
> TIA
> -Jim
 
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.