Hi,
I am having an issue deserializing a business object from a SQL stored
procedure. I have created the class using the XSD tool and the resulting
XMLDATA schema but when I try to create the object I get an error message
<[Object] xmlns=''was not expected.
As the XML being returned is an XML fragment due to not having a single root
element I have previously got around this issue by adding another table to
the database which acts purely as the root element. However, I would like to
do this properly rather than this bodge.
Very grateful for any advice. I am using SQL 2000 and version 1.1 of the
framework. 6 3628
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
Hi,
I am having an issue deserializing a business object from a SQL stored
procedure. I have created the class using the XSD tool and the resulting
XMLDATA schema but when I try to create the object I get an error message
<[Object] xmlns=''was not expected.
As the XML being returned is an XML fragment due to not having a single
root
element I have previously got around this issue by adding another table to
the database which acts purely as the root element. However, I would like
to
do this properly rather than this bodge.
Very grateful for any advice. I am using SQL 2000 and version 1.1 of the
framework.
I'd need more detail from you to give a good answer. Therefore, here's a bad
answer:
Rather than add another table to the database, I'd suggest you add a root
node to your XML. Create a new XmlDocument, add the root element to it, then
add your fragment as a child node of the root element. That should do it.
John
John,
Thanks for the response. What I am trying to do is return a business object
which I then use with XSLT to produce HTML. I am using an XMLReader in
conjunction with the SqlCommand object like so:
' Load data into Reader
Dim XMLR As System.Xml.XmlReader = sqlcom.ExecuteXmlReader
' Create an XmlSerializer
Dim Serializer As New XmlSerializer(GetType(Employee))
' Deserialize the data into the Projects instance
Dim Employee As Employee = CType(Serializer.Deserialize(XMLR),
Employee )
' Close reader
XMLR.Close()
Return Employee
The stored procedure associated with the SqlCommand object is returning data
using FOR XML. The Employee class has been created using XSD.exe.
Hopefully this has helped?
"John Saunders" wrote:
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:59**********************************@microsof t.com...
Hi,
I am having an issue deserializing a business object from a SQL stored
procedure. I have created the class using the XSD tool and the resulting
XMLDATA schema but when I try to create the object I get an error message
<[Object] xmlns=''was not expected.
As the XML being returned is an XML fragment due to not having a single
root
element I have previously got around this issue by adding another table to
the database which acts purely as the root element. However, I would like
to
do this properly rather than this bodge.
Very grateful for any advice. I am using SQL 2000 and version 1.1 of the
framework.
I'd need more detail from you to give a good answer. Therefore, here's a bad
answer:
Rather than add another table to the database, I'd suggest you add a root
node to your XML. Create a new XmlDocument, add the root element to it, then
add your fragment as a child node of the root element. That should do it.
John
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:38**********************************@microsof t.com...
John,
Thanks for the response. What I am trying to do is return a business
object
which I then use with XSLT to produce HTML. I am using an XMLReader in
conjunction with the SqlCommand object like so:
' Load data into Reader
Dim XMLR As System.Xml.XmlReader = sqlcom.ExecuteXmlReader
' Create an XmlSerializer
Dim Serializer As New XmlSerializer(GetType(Employee))
' Deserialize the data into the Projects instance
Dim Employee As Employee = CType(Serializer.Deserialize(XMLR),
Employee )
' Close reader
XMLR.Close()
Return Employee
The stored procedure associated with the SqlCommand object is returning
data
using FOR XML. The Employee class has been created using XSD.exe.
Hopefully this has helped?
It has helped, but you still haven't said;
1) What code you execute
2) What exception is thrown
3) What XML you're using
Also, are you returning only one Employee? If so, then I don't see why you
need another root. Why can't you treat Employee as the root, which is what
the XML Serializer will do?
John
John,
The code executed is that below, "the exception is <employee xmlns=""not
expected" and no I am returning mutliple Employees each of whom have elements
within them. Thanks
"John Saunders" wrote:
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:38**********************************@microsof t.com...
John,
Thanks for the response. What I am trying to do is return a business
object
which I then use with XSLT to produce HTML. I am using an XMLReader in
conjunction with the SqlCommand object like so:
' Load data into Reader
Dim XMLR As System.Xml.XmlReader = sqlcom.ExecuteXmlReader
' Create an XmlSerializer
Dim Serializer As New XmlSerializer(GetType(Employee))
' Deserialize the data into the Projects instance
Dim Employee As Employee = CType(Serializer.Deserialize(XMLR),
Employee )
' Close reader
XMLR.Close()
Return Employee
The stored procedure associated with the SqlCommand object is returning
data
using FOR XML. The Employee class has been created using XSD.exe.
Hopefully this has helped?
It has helped, but you still haven't said;
1) What code you execute
2) What exception is thrown
3) What XML you're using
Also, are you returning only one Employee? If so, then I don't see why you
need another root. Why can't you treat Employee as the root, which is what
the XML Serializer will do?
John
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
John,
The code executed is that below, "the exception is <employee xmlns=""not
expected" and no I am returning mutliple Employees each of whom have
elements
within them. Thanks
I bet this would work if there were only one Employee. Try this using a
query which will return only one, and see what happens. If it works, then
the exception will have been about the second <employeeelement.
In that case, you should next try using a serializer initialized for an
array of Employee. It's possible that will work.
If not, I think you'll have to use the override features of the serializer
to specify that you're dealing with an array Employee. I haven't done this
before, but in code I'd do something like this;
[XmlArray("employees")]
[XmlArrayItem("employee")]
You'd also have to get all the <employeeelements wrapped in an <employees>
element.
John
John,
Thanks for taking the time to respond, will try using the XmlArray. Thanks.
"John Saunders" wrote:
"Redowl" <Re****@discussions.microsoft.comwrote in message
news:FD**********************************@microsof t.com...
John,
The code executed is that below, "the exception is <employee xmlns=""not
expected" and no I am returning mutliple Employees each of whom have
elements
within them. Thanks
I bet this would work if there were only one Employee. Try this using a
query which will return only one, and see what happens. If it works, then
the exception will have been about the second <employeeelement.
In that case, you should next try using a serializer initialized for an
array of Employee. It's possible that will work.
If not, I think you'll have to use the override features of the serializer
to specify that you're dealing with an array Employee. I haven't done this
before, but in code I'd do something like this;
[XmlArray("employees")]
[XmlArrayItem("employee")]
You'd also have to get all the <employeeelements wrapped in an <employees>
element.
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Carl Mercier |
last post by:
Hi!
I have 2 different applications/assembly. The first one creates an
object and serializes it to a textfile on disk.
The second one has the the exact same class (copied/pasted). It reads...
|
by: Ian Tompsett |
last post by:
H
I was wondering if it possible for an object to serialize/deserialize itself from XML.
I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a...
|
by: Alex |
last post by:
I am creating an application that allows the user to link a plug-in
"utility" class (Watcher) to a class at runtime. There are several
Watcher utilities, each with a different style of "watching"...
|
by: PCH |
last post by:
I have 2 functions, one to serialize an object, and one to deserialize it.
I can serialize just fine, the problem is when I try to deserialize it
later...
I get an error:
{"Invalid...
|
by: George Addison |
last post by:
I understand this might not be the optimal method of
deserialization, but how can I deserialize a class to
itself? Something like:
Public Sub New(Optional ByVal filename as string =
Nothing)...
| |
by: Matt S |
last post by:
Hello,
I'm trying to build a C# client to consume an AXIS Web Service (running SOAP
over HTTP). The Web Service encodes
full server-side exception traces in the Soap Fault > Detail element...
|
by: Thomas S |
last post by:
Any suggestions on how to deserialize an object from one line of XML?
I'm trying to deserialize multiple objects from one XML document, each
object on one line of the file. The serialization is...
|
by: sankaralingam |
last post by:
I have a xml file created from Excel. I need to transfer the content to a collection of objects in VB.net. I am new to VB.net and XML i couldn't proceed further. I am getting a exception "There is...
|
by: connectpalm03-forum |
last post by:
I have a class named (MyClassA) in ControlClasses.dll and was able to
serialize it to database. Like below
SaveTo(MemoryStream stream)
{
IFormatter formatter = new BinaryFormatter();
...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |