473,396 Members | 1,864 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,396 software developers and data experts.

Reading XML from Database - Serious Problem - Need Help

This is long, but it's driving me nuts. I need some adult supervision :-)
(and I'm not above bribing for help)

I have a stored procedure that I call that returns XML to me. The SP returns
3 recordsets. The first comes as a single XML tag like this:

<row recordfound="1" IsExpired="0" />

The second has any number of recordsets that look like this:

<contact>
<contacttype>Individual</contacttype>
<fname>Fred</fname>
<lname>Flintstone</lname>
</contact>

And the third has any number of recordsets that look like this:

<nameservers>
<ns>ns1.example.com</ns>
</nameserver>

The ultimate goal here is to understand what the XML looks like coming out
of the SP, so I can deserialize it into the appropriate classes before I
play with it. Deserialization, I think I understand somewhat. But it's
failing - so I tried to consume this information in a number of different
ways, and each way shows me DIFFERENT STUFF. I'm baffled. Here are my
different ways, and what they produce:

The first way I tried was to use ExecuteReader() on my command, and then
build the output using a loop, as such:

StringBuilder sb = new StringBuilder();
do
{
while (r.Read())
{
for (int i = 0; i < r.FieldCount; i++)
sb.Append(r.GetString(i));
}
} while (r.NextResult());

return sb.ToString();

This returns me all of the XML tags that I expect, as I outlined, above.
First the <row> element, then a bunch of <contact> elements, and then some
<nameserver> elements. It looks just like I'd expect. So why isn't
deserialization working? I decided to look at it in a more "raw" way. Then
it got weird. I used a DataSet and spat out the XML that the DataSet had.
For some reason, all of the angle-bracket tags are, in the string, replaced
with their HTML-encoding equivelents. I have no idea why. The most confusing
part of this is that the output has extra tags that I don't understand! The
output actually looks like this:

<NewDataSet>
<Table>
<XML_F7384B61-2837-1243-B105-99384F8438B><row recordfound="1"
IsExpired="0" /></XML_F7384B61-2837-1243-B105-99384F8438B>
</Table>
<Table1>
<XML_F7384B61-2837-1243-B105-99384F8438B>
<contact>
<contacttype>Individual</contacttype>
<fname>Fred</fname>
<lname>Flintstone</lname>
</contact>
</XML_F7384B61-2837-1243-B105-99384F8438B>
</Table1>
<Table1>
<XML_F7384B61-2837-1243-B105-99384F8438B>
<contact>
<contacttype>Individual</contacttype>
<fname>Wilma</fname>
<lname>Flintstone</lname>
</contact>
</XML_F7384B61-2837-1243-B105-99384F8438B>
</Table1>

.... and so on ...
</NewDataSet>

I have no idea what NewDataSet is, or the XML_[guid] tag is, though I must
presume that the SQL server is inserting them. Could this be why
deserialization is failing?

Here's the code that generates this output:

public string DataSetMethod(string domain)
{
this.sqlConnection.Open();
this.mySQLCommand.Parameters["@strDomainName"].Value = domain;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(this.sqlWHOIS);
da.Fill(ds);
StringWriter sr = new StringWriter();
ds.WriteXml(sr);
this.sqlConnection.Close();
string result = sr.ToString();

// Note that I have to do this replace, because the < and > are replaced
with &lt; and &gt; ... confusing.

return result.Replace("&lt;", "<").Replace("&gt;", ">");
}

The reason I'm so confused here is, as I said, that I want to deserialize
all of this. I've created the appropriate classes, but it constantly fails,
with CanDeserialize() always returning false. The curious thing is, before
we added the first recordset (with the single tag that has attributes but no
data), it worked just fine. Is this a clue?

Knowing what my "contact" tag looks like, I should be able to deserialize
into this:

[Serializable]
public class Contact
{
public string ContactType;
public string FName;
public string LName;
}

And I should be able to do this:

XmlSerializer ser = new XmlSerializer(typeof(Contact));
XmlTextReader r = (XmlTextReader)this.mySQLCommand.ExecuteXmlReader( );

if (ser.CanDeserialize(r))
{
Contact c = (Contact)ser.Deserialize(r));
}
else
{
ReportError("Cannot deserialize Contact");
}

But no. It fails, and reports the "Cannot deserialize Contact" error.

So... to summarize my confusion:

What's the extra junk that SQL server is sending down?
Why, when I get the XML out of the DataSet are all of the angle brackets
replaced with their HTML-encoded equivelents?
And why is CanDeserialize() always telling me that it doesn't like my
contact class, when it looks correct?!

If I could just get this working, I think I understand how I make a root
class that holds a collection of Contact and Nameserver classes, to
deserialize all of the XML into, so I can pass an instance of the class back
out to my program to play with.

HELP?!

Christopher

Nov 11 '05 #1
0 3542

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

Similar topics

5
by: democratix | last post by:
Hi, I've only got a couple years experience developing for Access but have recently been experimenting with HTML/javascript for gui and client-side scripting, mysql for database and php for...
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
2
by: Dan | last post by:
Hello. I have recently tried upgrading the MySql connector for my servlet from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was hoping that 3.0.9 would fix it. However, now I...
3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
346
by: rkusenet | last post by:
http://biz.yahoo.com/rc/040526/tech_database_marketshare_1.html Interesting to see that database sales for windows is more than Unix.
5
by: ajitp | last post by:
Hi, I am having serious trouble retreiving a blob from a oracle table. The pictures are stored in the database and I need to retreive the pictures and display it on a page. Can anyone help me...
11
by: bgreen | last post by:
I am hoping for some assistance with formatting a large text file which consists of a series of individual records. Each record includes specific labels/field names (a sample of 1 record (one of...
0
by: AboShorouq | last post by:
Hi, i'am new to this group, so i don't know how the things going on here. i have a serious problem and any help from you guys is very appreciated. i am trying to read data from db2 v8 on AIX...
10
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Not sure if I quite follow that. 1....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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,...

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.