473,438 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,438 software developers and data experts.

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="value111" column12="value112" column13="value113" />
<table1 column12="value121" column2="value122" column3="value123" />
<table2 column21="value211" column2="value212" column3="value213" />
<table2 column22="value221" column2="value222" column3="value223" />
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 3574
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="value111" column12="value112" column13="value113" />
<table1 column12="value121" column2="value122" column3="value123" />
<table2 column21="value211" column2="value212" column3="value213" />
<table2 column22="value221" column2="value222" column3="value223" />
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\\myDB.xsd";
string myXmlDir = "C:\\myDir\\myDB.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.LoadXml(xmlSchema);
xmlLoadSchema.Save(myXsdDir);

DataSet xmlDS = new DataSet("myDB");
xmlDS.ReadXmlSchema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunction(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().Trim() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.LoadXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Save(myXmlDir);

xmlDS.ReadXml(myXmlDir);

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="value111" column12="value112" column13="value113" />
<table1 column12="value121" column2="value122" column3="value123" />
<table2 column21="value211" column2="value212" column3="value213" />
<table2 column22="value221" column2="value222" column3="value223" />
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\\myDB.xsd";
string myXmlDir = "C:\\myDir\\myDB.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.LoadXml(xmlSchema);
xmlLoadSchema.Save(myXsdDir);

DataSet xmlDS = new DataSet("myDB");
xmlDS.ReadXmlSchema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunction(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().Trim() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.LoadXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Save(myXmlDir);

xmlDS.ReadXml(myXmlDir);

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="value111" column12="value112" column13="value113" />
<table1 column12="value121" column2="value122" column3="value123" />
<table2 column21="value211" column2="value212" column3="value213" />
<table2 column22="value221" column2="value222" column3="value223" />
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\\myDB.xsd";
string myXmlDir = "C:\\myDir\\myDB.xml";

XmlDocument xmlLoadSchema = new XmlDocument();
xmlLoadSchema.LoadXml(xmlSchema);
xmlLoadSchema.Save(myXsdDir);

DataSet xmlDS = new DataSet("myDB");
xmlDS.ReadXmlSchema(myXsdDir);

DataTable xmlDT = new DataTable();
xmlDT = myExternalFunction(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().Trim() + "</ROOT>";

XmlDocument xmlLoadData = new XmlDocument();
xmlLoadData.LoadXml(xmlData); // <-- I assume the bombing is here
xmlLoadData.Save(myXmlDir);

xmlDS.ReadXml(myXmlDir);

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="value111" column12="value112" column13="value113" />
> <table1 column12="value121" column2="value122" column3="value123" />
> <table2 column21="value211" column2="value212" column3="value213" />
> <table2 column22="value221" column2="value222" column3="value223" />
> 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
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...
3
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...
1
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...
3
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...
0
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...
3
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!...
7
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
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...
0
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 ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.