XML invalid characters in dataset

G

Guest

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!
 
G

Guest

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
 
G

Guest

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 said:
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 said:
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!
 
G

Guest

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 said:
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 said:
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 said:
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!
 
G

Guest

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 said:
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 said:
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 said:
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




:

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!
 

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

Top