XML -best method to read/write in NETcf??

M

mikeb

I'm trying to use XML to send data to / from a scanner (ppc). Our current
vb netcf app connects directly with the sqlserver - however some scanners
have no network access and the SQLserver is in another location - the host
application developers are asking us to give the scanners options to
import/export data via xml files - the xml files will be sent via archaic
means. They are letting us spec the xml files.

For XML being THE thing, it sure is proving to be a pain getting this all
working. Basically, I our netcf app is working under this scenario:

To receive data from sql server into ppc
(SQLserver data)->SQLStoredProcedure -->PPCdataset->SQLceDB

To send updated data from ppc into sql server
SQLceDB--> SQLStoredProcedure->(SQLserver data)


Similarly I need to remove the stored procedure call and replace it with XML
import/exports.

Receive data from xml into ppc
XMLfile -->PPCdataset->SQLceDB

Send updated data from ppc into xml
SQLceDB--> XMLfile


I have been able to do a test by reading the sql server data into a dataset
via the stored procedure (using a data adapter) - and then writing that out
to XML [ ds.WriteXml("test.xml") ]

Ok, that gave me a test XML file to play with - but I can't even read that
XML file in to a dataset now. Trying to use:
Dim XMLreader as New XmlTextReader(New StreamReader("test.xml")
dsXML.ReadXmlSchema(XMLreader)
dsXML.ReadXml(XMLreader)

Are there any sample programs out there that contain a sample XML file that
gets read into a dataset, and then maybe even exports an xml file containing
modified data?

I'm trying to do my homework - but dang. It just seems that if XML is the
thing these days, it would be easier than this. Flat ascii files are sure
easier and even make more sense to the naked eye. ??

Thanks for any guidance.
 
I

Ilya Tumanov [MS]

ds.WriteXml("test.xml") won't write schema, so attempt to read it via
dsXML.ReadXmlSchema(XMLreader) would sure fail.

Use DataSet.WriteXml() overload which takes XmlWriteMode and specify
XmlWriteMode.WriteSchema to ensure schema has been included.

To read it back simply use ds.ReadXml("fileName"), it would recognize and
load schema automatically.



Also, keep in mind there are no relative paths on CF and you have to specify
the exact location for a saved file.


Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
M

mikeb

I tried as you described, but am still getting a NullReferenceException when
I try to read the xml file into my dataset.


XMLfname is defined as follows:
XMLfname as string = "\My Documents\VTTK.xml"

Per VS Help's sample code, I'm successfully writing out an xml file to the
MyDocuments folder using the following code:

Try
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(XMLfname, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim XMLwriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
dsVTTK.WriteXml(XmlWriter, XmlWriteMode.WriteSchema)

....But, when I try to read it in (code follows), I am getting a Null
Reference Exception. What does the NRException mean? And I am trying to
look this up on my own here.

Try
Dim XMLreader As New XmlTextReader(New StreamReader(XMLfname))
dsXMLVTTK.ReadXml(XMLfname)



Am I doing something blatently wrong?

Thanks.


Ilya Tumanov said:
ds.WriteXml("test.xml") won't write schema, so attempt to read it via
dsXML.ReadXmlSchema(XMLreader) would sure fail.

Use DataSet.WriteXml() overload which takes XmlWriteMode and specify
XmlWriteMode.WriteSchema to ensure schema has been included.

To read it back simply use ds.ReadXml("fileName"), it would recognize and
load schema automatically.



Also, keep in mind there are no relative paths on CF and you have to
specify the exact location for a saved file.


Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

mikeb said:
I'm trying to use XML to send data to / from a scanner (ppc). Our
current vb netcf app connects directly with the sqlserver - however some
scanners have no network access and the SQLserver is in another
location - the host application developers are asking us to give the
scanners options to import/export data via xml files - the xml files will
be sent via archaic means. They are letting us spec the xml files.

For XML being THE thing, it sure is proving to be a pain getting this all
working. Basically, I our netcf app is working under this scenario:

To receive data from sql server into ppc
(SQLserver data)->SQLStoredProcedure -->PPCdataset->SQLceDB

To send updated data from ppc into sql server
SQLceDB--> SQLStoredProcedure->(SQLserver data)


Similarly I need to remove the stored procedure call and replace it with
XML import/exports.

Receive data from xml into ppc
XMLfile -->PPCdataset->SQLceDB

Send updated data from ppc into xml
SQLceDB--> XMLfile


I have been able to do a test by reading the sql server data into a
dataset via the stored procedure (using a data adapter) - and then
writing that out to XML [ ds.WriteXml("test.xml") ]

Ok, that gave me a test XML file to play with - but I can't even read
that XML file in to a dataset now. Trying to use:
Dim XMLreader as New XmlTextReader(New StreamReader("test.xml")
dsXML.ReadXmlSchema(XMLreader)
dsXML.ReadXml(XMLreader)

Are there any sample programs out there that contain a sample XML file
that gets read into a dataset, and then maybe even exports an xml file
containing modified data?

I'm trying to do my homework - but dang. It just seems that if XML is
the thing these days, it would be easier than this. Flat ascii files are
sure easier and even make more sense to the naked eye. ??

Thanks for any guidance.
 
I

Ilya Tumanov [MS]

NullReferenceException means you have a reference, but it points to Nothing.



Analogy would be a pocket with something in it, say a cell phone.

If you'd like to make a call, you reach a cell in your pocket.

But if you forget cell at home, that won't work even though you pocket is
with you and it suppose to contain a cell.



Few examples:



Dim ds As DataSet << That's just a reference, no object has
been created

ds.ReadXml("whatever") << You get NullReferenceException here as there's
no DataSet and 'ds' is null (Nothing in VB).

--------

Dim ds As New DataSet() << Declare a reference and create an object

ds.ReadXml("whatever") << That would work as DataSet exists.

--------

Dim ds As DataSet << That's just a reference, no object has
been created

Ds = New DataSet() << Create an object

ds.ReadXml("whatever") << That would also work.

--------



Best regards,



Ilya



This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

mikeb said:
I tried as you described, but am still getting a NullReferenceException
when I try to read the xml file into my dataset.


XMLfname is defined as follows:
XMLfname as string = "\My Documents\VTTK.xml"

Per VS Help's sample code, I'm successfully writing out an xml file to the
MyDocuments folder using the following code:

Try
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(XMLfname, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim XMLwriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
dsVTTK.WriteXml(XmlWriter, XmlWriteMode.WriteSchema)

...But, when I try to read it in (code follows), I am getting a Null
Reference Exception. What does the NRException mean? And I am trying to
look this up on my own here.

Try
Dim XMLreader As New XmlTextReader(New StreamReader(XMLfname))
dsXMLVTTK.ReadXml(XMLfname)



Am I doing something blatently wrong?

Thanks.


Ilya Tumanov said:
ds.WriteXml("test.xml") won't write schema, so attempt to read it via
dsXML.ReadXmlSchema(XMLreader) would sure fail.

Use DataSet.WriteXml() overload which takes XmlWriteMode and specify
XmlWriteMode.WriteSchema to ensure schema has been included.

To read it back simply use ds.ReadXml("fileName"), it would recognize and
load schema automatically.



Also, keep in mind there are no relative paths on CF and you have to
specify the exact location for a saved file.


Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

mikeb said:
I'm trying to use XML to send data to / from a scanner (ppc). Our
current vb netcf app connects directly with the sqlserver - however some
scanners have no network access and the SQLserver is in another
location - the host application developers are asking us to give the
scanners options to import/export data via xml files - the xml files
will be sent via archaic means. They are letting us spec the xml files.

For XML being THE thing, it sure is proving to be a pain getting this
all working. Basically, I our netcf app is working under this scenario:

To receive data from sql server into ppc
(SQLserver data)->SQLStoredProcedure -->PPCdataset->SQLceDB

To send updated data from ppc into sql server
SQLceDB--> SQLStoredProcedure->(SQLserver data)


Similarly I need to remove the stored procedure call and replace it with
XML import/exports.

Receive data from xml into ppc
XMLfile -->PPCdataset->SQLceDB

Send updated data from ppc into xml
SQLceDB--> XMLfile


I have been able to do a test by reading the sql server data into a
dataset via the stored procedure (using a data adapter) - and then
writing that out to XML [ ds.WriteXml("test.xml") ]

Ok, that gave me a test XML file to play with - but I can't even read
that XML file in to a dataset now. Trying to use:
Dim XMLreader as New XmlTextReader(New StreamReader("test.xml")
dsXML.ReadXmlSchema(XMLreader)
dsXML.ReadXml(XMLreader)

Are there any sample programs out there that contain a sample XML file
that gets read into a dataset, and then maybe even exports an xml file
containing modified data?

I'm trying to do my homework - but dang. It just seems that if XML is
the thing these days, it would be easier than this. Flat ascii files
are sure easier and even make more sense to the naked eye. ??

Thanks for any guidance.
 
G

Guest

You don't need to call ReadXmlSchema if you use the ReadXml.

Could you try just to call ReadXml and pass it a file name?
 
M

mikeb

I think this is where I run and climb under a bush to hide for the rest of
the day.

Thanks, very much appreciated - I completely overlooked the creation of the
dataset object.

Now pardon me while I slip under this holly bush....


Ilya Tumanov said:
NullReferenceException means you have a reference, but it points to
Nothing.



Analogy would be a pocket with something in it, say a cell phone.

If you'd like to make a call, you reach a cell in your pocket.

But if you forget cell at home, that won't work even though you pocket is
with you and it suppose to contain a cell.



Few examples:



Dim ds As DataSet << That's just a reference, no object
has been created

ds.ReadXml("whatever") << You get NullReferenceException here as there's
no DataSet and 'ds' is null (Nothing in VB).

--------

Dim ds As New DataSet() << Declare a reference and create an object

ds.ReadXml("whatever") << That would work as DataSet exists.

--------

Dim ds As DataSet << That's just a reference, no object
has been created

Ds = New DataSet() << Create an object

ds.ReadXml("whatever") << That would also work.

--------



Best regards,



Ilya



This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

mikeb said:
I tried as you described, but am still getting a NullReferenceException
when I try to read the xml file into my dataset.


XMLfname is defined as follows:
XMLfname as string = "\My Documents\VTTK.xml"

Per VS Help's sample code, I'm successfully writing out an xml file to
the MyDocuments folder using the following code:

Try
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(XMLfname, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim XMLwriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
dsVTTK.WriteXml(XmlWriter, XmlWriteMode.WriteSchema)

...But, when I try to read it in (code follows), I am getting a Null
Reference Exception. What does the NRException mean? And I am trying to
look this up on my own here.

Try
Dim XMLreader As New XmlTextReader(New StreamReader(XMLfname))
dsXMLVTTK.ReadXml(XMLfname)



Am I doing something blatently wrong?

Thanks.


Ilya Tumanov said:
ds.WriteXml("test.xml") won't write schema, so attempt to read it via
dsXML.ReadXmlSchema(XMLreader) would sure fail.

Use DataSet.WriteXml() overload which takes XmlWriteMode and specify
XmlWriteMode.WriteSchema to ensure schema has been included.

To read it back simply use ds.ReadXml("fileName"), it would recognize
and load schema automatically.



Also, keep in mind there are no relative paths on CF and you have to
specify the exact location for a saved file.


Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

I'm trying to use XML to send data to / from a scanner (ppc). Our
current vb netcf app connects directly with the sqlserver - however
some scanners have no network access and the SQLserver is in another
location - the host application developers are asking us to give the
scanners options to import/export data via xml files - the xml files
will be sent via archaic means. They are letting us spec the xml
files.

For XML being THE thing, it sure is proving to be a pain getting this
all working. Basically, I our netcf app is working under this
scenario:

To receive data from sql server into ppc
(SQLserver data)->SQLStoredProcedure -->PPCdataset->SQLceDB

To send updated data from ppc into sql server
SQLceDB--> SQLStoredProcedure->(SQLserver data)


Similarly I need to remove the stored procedure call and replace it
with XML import/exports.

Receive data from xml into ppc
XMLfile -->PPCdataset->SQLceDB

Send updated data from ppc into xml
SQLceDB--> XMLfile


I have been able to do a test by reading the sql server data into a
dataset via the stored procedure (using a data adapter) - and then
writing that out to XML [ ds.WriteXml("test.xml") ]

Ok, that gave me a test XML file to play with - but I can't even read
that XML file in to a dataset now. Trying to use:
Dim XMLreader as New XmlTextReader(New StreamReader("test.xml")
dsXML.ReadXmlSchema(XMLreader)
dsXML.ReadXml(XMLreader)

Are there any sample programs out there that contain a sample XML file
that gets read into a dataset, and then maybe even exports an xml file
containing modified data?

I'm trying to do my homework - but dang. It just seems that if XML is
the thing these days, it would be easier than this. Flat ascii files
are sure easier and even make more sense to the naked eye. ??

Thanks for any guidance.
 

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

Similar Threads


Top