473,542 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML invalid characters in dataset

Hello... I'm a rookie to c#. So let me see if i can expose properly my
situation.

I developed a stored procedure in sql server 2000 that allows me to
construct my dataset in XML format. the sp's output will look something
similar to this:

<table1 column11="value 111" column12="value 112" column13="value 113" />
<table1 column12="value 121" column2="value1 22" column3="value1 23" />
<table2 column21="value 211" column2="value2 12" column3="value2 13" />
<table2 column22="value 221" column2="value2 22" column3="value2 23" />
etc. etc. etc.

What I'm trying to do is to take this xml data and store it into a dataset
in c#. I understand that I first must append this data (the sp's output)
with the xml root and namespace, so that an XmlReader can interpret it as
legitimate XML data without exploding.

What I was trying to do is to convert this dataset (the one from the sp)
into a string variable and then appending it to a character string that
literally (manually) contains both the root and namespace, something like
this:

(let's assume dt is a datatable object that only contains one column and one
row, being that cell the string representation of my xml data from the sp)

(also, let's assume myDB.xsd is a valid DB schema file in which the data
will be placed. The DB schema XML representation is working fine. The problem
is the data itself)

string myStr = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
dt.Rows[0][0].ToString() + "</ROOT>";

It seems to me that this doesn't work given I get an error which tells me
that the ">" character is invalid.

Would you please help me? If you need more information, just let me know.

Thanks!
Feb 7 '06 #1
4 3584
J.C.,
Why don't you try using the DataSet class ReadXml method? It has some
overloads that control schema inference etc. behavior. You may be able to
load the xml string directly.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:
Hello... I'm a rookie to c#. So let me see if i can expose properly my
situation.

I developed a stored procedure in sql server 2000 that allows me to
construct my dataset in XML format. the sp's output will look something
similar to this:

<table1 column11="value 111" column12="value 112" column13="value 113" />
<table1 column12="value 121" column2="value1 22" column3="value1 23" />
<table2 column21="value 211" column2="value2 12" column3="value2 13" />
<table2 column22="value 221" column2="value2 22" column3="value2 23" />
etc. etc. etc.

What I'm trying to do is to take this xml data and store it into a dataset
in c#. I understand that I first must append this data (the sp's output)
with the xml root and namespace, so that an XmlReader can interpret it as
legitimate XML data without exploding.

What I was trying to do is to convert this dataset (the one from the sp)
into a string variable and then appending it to a character string that
literally (manually) contains both the root and namespace, something like
this:

(let's assume dt is a datatable object that only contains one column and one
row, being that cell the string representation of my xml data from the sp)

(also, let's assume myDB.xsd is a valid DB schema file in which the data
will be placed. The DB schema XML representation is working fine. The problem
is the data itself)

string myStr = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
dt.Rows[0][0].ToString() + "</ROOT>";

It seems to me that this doesn't work given I get an error which tells me
that the ">" character is invalid.

Would you please help me? If you need more information, just let me know.

Thanks!

Feb 7 '06 #2
Greetings, Peter.
Sorry for not being a bit more explicit on what I did.

Let me copy/paste a sample of my code so that you have a clearer idea.
You'll see that indeed I used the ReadXml function.

This is my code:

public DataSet myDSFunc(int myInt, string xmlSchema)
{
string myXsdDir = "C:\\myDir\\myD B.xsd";
string myXmlDir = "C:\\myDir\\myD B.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.L oadXml(xmlSchem a);
xmlLoadSchema.S ave(myXsdDir);

DataSet xmlDS = new DataSet("myDB") ;
xmlDS.ReadXmlSc hema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunct ion(myInt); // This function returns the 1x1
DataTable that I mentioned in my first post; that single cell contains a
string with the XML representation of my retrieved data.

string xmlData = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
xmlDT.Rows[0][0].ToString().Tri m() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.Loa dXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Sav e(myXmlDir);

xmlDS.ReadXml(m yXmlDir);

return xmlDS;
}

Is it a bit clear now? Please advise.

J.C.
"Peter Bromberg [C# MVP]" wrote:
J.C.,
Why don't you try using the DataSet class ReadXml method? It has some
overloads that control schema inference etc. behavior. You may be able to
load the xml string directly.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:
Hello... I'm a rookie to c#. So let me see if i can expose properly my
situation.

I developed a stored procedure in sql server 2000 that allows me to
construct my dataset in XML format. the sp's output will look something
similar to this:

<table1 column11="value 111" column12="value 112" column13="value 113" />
<table1 column12="value 121" column2="value1 22" column3="value1 23" />
<table2 column21="value 211" column2="value2 12" column3="value2 13" />
<table2 column22="value 221" column2="value2 22" column3="value2 23" />
etc. etc. etc.

What I'm trying to do is to take this xml data and store it into a dataset
in c#. I understand that I first must append this data (the sp's output)
with the xml root and namespace, so that an XmlReader can interpret it as
legitimate XML data without exploding.

What I was trying to do is to convert this dataset (the one from the sp)
into a string variable and then appending it to a character string that
literally (manually) contains both the root and namespace, something like
this:

(let's assume dt is a datatable object that only contains one column and one
row, being that cell the string representation of my xml data from the sp)

(also, let's assume myDB.xsd is a valid DB schema file in which the data
will be placed. The DB schema XML representation is working fine. The problem
is the data itself)

string myStr = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
dt.Rows[0][0].ToString() + "</ROOT>";

It seems to me that this doesn't work given I get an error which tells me
that the ">" character is invalid.

Would you please help me? If you need more information, just let me know.

Thanks!

Feb 7 '06 #3
J.C.,
Suggest that you Save the string xmlData to the filesystem with an .xml
extension and then double-click in Windows Explorer to load into Internet
Explorer. IE will show you exactly where the invalid markup is.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:
Greetings, Peter.
Sorry for not being a bit more explicit on what I did.

Let me copy/paste a sample of my code so that you have a clearer idea.
You'll see that indeed I used the ReadXml function.

This is my code:

public DataSet myDSFunc(int myInt, string xmlSchema)
{
string myXsdDir = "C:\\myDir\\myD B.xsd";
string myXmlDir = "C:\\myDir\\myD B.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.L oadXml(xmlSchem a);
xmlLoadSchema.S ave(myXsdDir);

DataSet xmlDS = new DataSet("myDB") ;
xmlDS.ReadXmlSc hema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunct ion(myInt); // This function returns the 1x1
DataTable that I mentioned in my first post; that single cell contains a
string with the XML representation of my retrieved data.

string xmlData = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
xmlDT.Rows[0][0].ToString().Tri m() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.Loa dXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Sav e(myXmlDir);

xmlDS.ReadXml(m yXmlDir);

return xmlDS;
}

Is it a bit clear now? Please advise.

J.C.
"Peter Bromberg [C# MVP]" wrote:
J.C.,
Why don't you try using the DataSet class ReadXml method? It has some
overloads that control schema inference etc. behavior. You may be able to
load the xml string directly.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:
Hello... I'm a rookie to c#. So let me see if i can expose properly my
situation.

I developed a stored procedure in sql server 2000 that allows me to
construct my dataset in XML format. the sp's output will look something
similar to this:

<table1 column11="value 111" column12="value 112" column13="value 113" />
<table1 column12="value 121" column2="value1 22" column3="value1 23" />
<table2 column21="value 211" column2="value2 12" column3="value2 13" />
<table2 column22="value 221" column2="value2 22" column3="value2 23" />
etc. etc. etc.

What I'm trying to do is to take this xml data and store it into a dataset
in c#. I understand that I first must append this data (the sp's output)
with the xml root and namespace, so that an XmlReader can interpret it as
legitimate XML data without exploding.

What I was trying to do is to convert this dataset (the one from the sp)
into a string variable and then appending it to a character string that
literally (manually) contains both the root and namespace, something like
this:

(let's assume dt is a datatable object that only contains one column and one
row, being that cell the string representation of my xml data from the sp)

(also, let's assume myDB.xsd is a valid DB schema file in which the data
will be placed. The DB schema XML representation is working fine. The problem
is the data itself)

string myStr = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
dt.Rows[0][0].ToString() + "</ROOT>";

It seems to me that this doesn't work given I get an error which tells me
that the ">" character is invalid.

Would you please help me? If you need more information, just let me know.

Thanks!

Feb 8 '06 #4
Greetings, Peter... Sorry for my delay.

Would you please give me the command to save the xmlData string in the
filesystem? I assume this one is different from the .Save method for an
XmlDocument object, right?

Thanks!

J.C.
"Peter Bromberg [C# MVP]" wrote:
J.C.,
Suggest that you Save the string xmlData to the filesystem with an .xml
extension and then double-click in Windows Explorer to load into Internet
Explorer. IE will show you exactly where the invalid markup is.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:
Greetings, Peter.
Sorry for not being a bit more explicit on what I did.

Let me copy/paste a sample of my code so that you have a clearer idea.
You'll see that indeed I used the ReadXml function.

This is my code:

public DataSet myDSFunc(int myInt, string xmlSchema)
{
string myXsdDir = "C:\\myDir\\myD B.xsd";
string myXmlDir = "C:\\myDir\\myD B.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.L oadXml(xmlSchem a);
xmlLoadSchema.S ave(myXsdDir);

DataSet xmlDS = new DataSet("myDB") ;
xmlDS.ReadXmlSc hema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunct ion(myInt); // This function returns the 1x1
DataTable that I mentioned in my first post; that single cell contains a
string with the XML representation of my retrieved data.

string xmlData = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
xmlDT.Rows[0][0].ToString().Tri m() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.Loa dXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Sav e(myXmlDir);

xmlDS.ReadXml(m yXmlDir);

return xmlDS;
}

Is it a bit clear now? Please advise.

J.C.
"Peter Bromberg [C# MVP]" wrote:
J.C.,
Why don't you try using the DataSet class ReadXml method? It has some
overloads that control schema inference etc. behavior. You may be able to
load the xml string directly.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"J.C.Rivera " wrote:

> Hello... I'm a rookie to c#. So let me see if i can expose properly my
> situation.
>
> I developed a stored procedure in sql server 2000 that allows me to
> construct my dataset in XML format. the sp's output will look something
> similar to this:
>
> <table1 column11="value 111" column12="value 112" column13="value 113" />
> <table1 column12="value 121" column2="value1 22" column3="value1 23" />
> <table2 column21="value 211" column2="value2 12" column3="value2 13" />
> <table2 column22="value 221" column2="value2 22" column3="value2 23" />
> etc. etc. etc.
>
> What I'm trying to do is to take this xml data and store it into a dataset
> in c#. I understand that I first must append this data (the sp's output)
> with the xml root and namespace, so that an XmlReader can interpret it as
> legitimate XML data without exploding.
>
> What I was trying to do is to convert this dataset (the one from the sp)
> into a string variable and then appending it to a character string that
> literally (manually) contains both the root and namespace, something like
> this:
>
> (let's assume dt is a datatable object that only contains one column and one
> row, being that cell the string representation of my xml data from the sp)
>
> (also, let's assume myDB.xsd is a valid DB schema file in which the data
> will be placed. The DB schema XML representation is working fine. The problem
> is the data itself)
>
> string myStr = "<ROOT xmlns=\"http://blabla.org/myDB.xsd\"> +
> dt.Rows[0][0].ToString() + "</ROOT>";
>
> It seems to me that this doesn't work given I get an error which tells me
> that the ">" character is invalid.
>
> Would you please help me? If you need more information, just let me know.
>
> Thanks!

Feb 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8136
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones like Microsoft's 'smartquotes'), and outputs the file. The problem is these files will be on disk, so the program won't have the character encoding...
3
9170
by: RichW | last post by:
I've seen a couple other posts on this but no real answers. I'm trying to do a bulk insert and everything is fine until I run the objCom.ExecuteNonQuery() statement at which point I get the XML parsing error. Of course, it would be easy to simply wrap unicode characters with CDATA <!]> but is this doable when passing values to fields to...
1
3531
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string filename) method. I get an error that says the document contains invalid characters. The document loads fine with Chinese characters in a node value, but...
3
5613
by: Mohammad-Reza | last post by:
We are writing an application for a specific culture(Arabic or Farsi). This application involves using DataAdapter, OLEDB Connection and the DataSet. We didn't use the .NET data binding, just field TextBoxes with the data retrieved from the DataSet but whole system seems to be unable to update the database (.mdb file) with Unicode characters....
0
5686
by: Ben Holness | last post by:
Hi all, I have a system which allows users to enter a message on a (PHP) website. This message is then put into a (MySQL) Database. A perl script then picks up the message and creates an XML document. The webpages, database and XML are all UTF-8, however every now and then I get an error in the XML parser that tells me I have an invalid...
3
2195
by: Anders Jansson | last post by:
Hi all. I have 2 problems when I try to open and convert an ASP.NET VS 2003 web-applikation in VS 2005. In VS 2003 I have no problems at all! First: One subfolder with will not be converted! The converted web project are missing this subfolder completely. 39 errors are displayed in the Conversion Report saying: ERROR: Unable to get...
7
4894
by: Trac Bannon | last post by:
When I load XML from a file into a dotNet XMLDataDocument, the UTF-8 codes are resolved but the 5 special XML entities are not. How can I force those 5 special character types to be translated?
1
4174
mahet
by: mahet | last post by:
Anders Jansson was a guest here, and he was having problem: When I try to build the web, this error is displayed: ---> Error 5 Unable to convert input xml file content to a DataSet. Invalid 'name' attribute value 'Företag': 'The '¶' character, hexadecimal value 0xB6, at position 2 within the name, cannot be included in a name.'. <start...
0
883
by: abishflake | last post by:
Getting error "The surrogate pair is invalid."when serializing dataset to MemoryStream. Dataset contains some special characters like - and space code given below MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); ...
0
7571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7721
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5246
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
943
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.