471,605 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 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 3419
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Safalra | last post: by
3 posts views Thread by Mohammad-Reza | last post: by
reply views Thread by Ben Holness | last post: by
3 posts views Thread by Anders Jansson | last post: by
7 posts views Thread by Trac Bannon | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

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.