Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Schema dsCamTypeData.ReadXml(myReader, System.Data.XmlReadMode.);

Status
Not open for further replies.

skeletonatthefeast

Programmer
May 9, 2007
3
GB
Hi all,

I have just started programming in C# and hope to store relational db data in XML files.

When trying to load a file of xml data which adheres to the schema already loaded into my dataset, I get an exception that says "Data at the root level is invalid. Line 1, position 1876.". This occurs on the line dsCamTypeData.ReadXml(myReader, System.Data.XmlReadMode.ReadSchema);
from the code below. The schema appears to load in ok as I can add data to the xml file without a problem. The schema was created in visual studio 2005 visually as two tables.

I have only just started programming in c# and know very little about XML so I am hoping that the problem is something obvious that I am missing.

Thanks in anticipation!

if (File.Exists(fileName))
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
XmlTextReader myReader = new XmlTextReader(fs);
dsCamTypeData.Reset();
dsCamTypeData.ReadXml(myReader, System.Data.XmlReadMode.ReadSchema);
myReader.Close();
MessageBox.Show("File: " + fileName + ", was opened successfully");
 
Drop the xml and use a relational database instead.
MS SQL
MS Access
Oracel
Sybase
MySQL
PostGreSQL
Visual dBase

here are your problems with XML.
1. security
2. effeciency (very slow)
3. easily corrupted (it's just a text file)
4. update concurrency issues

XML was meant to transfer data between heterogenious systems, not meant as permenant data storage.

It's great for webservices, reporting meta data, and simple services, but it is not meant to replace a Relational Database.

As for your error: open the file go to Line 1 Character 1876 and determine why this is invalid. I'm guessing it's either a invalid character (not UTF8) or there is a syntax error.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi jmeckley,

Thanks for your response. The problem with using a relational database is that I believe there are associated license costs (I am using Windows CE). The tables I need to store will not have large number of records and at a later date, my device will need to act as a web server and these files must be modified remotely, via a browser and maybe naively, I thought XML may be the way to go.

With regard to the error, I have realized that when I run the same program on my pocket pc as opposed to the simulator, the exception does not occur. I am sure however, that the exception did not occur when I ran the program on a pocket pc simulator last week yet the problem now shows up, without any change to the software. It seems that something strange is going on.

I will investigate the xml file with the error although it was created with visual studio and it seems to be fine when my program is running and I add records, to do which, the schema is also accessed.

Thanks again for your help!
 
I also don't understand how there could be an error at character 1876 as the lines of my xsd file are much shorter. Also, it seems that the line with a problem apparently changes despite the xsd file staying constant. Here's an extract from the top of my xml schema.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1" targetNamespace=" elementFormDefault="qualified" xmlns=" xmlns:mstns=" xmlns:xs=" <xs:element name="CAMERA_TABLE">
<xs:complexType>
<xs:sequence>
 
There are licensing costs with the bigger dbs: MS SQL, Oracel, Sybase

MySql and PostgreSQL are open source. MS Access Must be installed where the database is to reside. Usually a server which the user can access.

I know MS offers MS SQL 2005 Express which is free to use. There are some hardware limitations but has the same functionality as Sql Server 2005. I believe Oracel also offers a free version similiar to MS.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top