469,946 Members | 1,782 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

Stream DataSet into XMLDocument

Hello,

I am trying to create a xmlDocument from as dataset. My code is listed
below. All seems to go well until
xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the
following error "The Root Element is Missing" ... any help would be
appreciated.

Thanks,
Rob Panosh

Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument
Dim ms As New System.IO.MemoryStream ' = Nothing
Dim ser As System.Xml.Serialization.XmlSerializer
Dim t As System.Type

t = GetType(System.Data.DataSet)
ser = New System.Xml.Serialization.XmlSerializer(t) '
System.Type.GetType("System.Data.DataSet"))

'Filled with data adapter.
Me.Execute(xDataSet, "test")

ser.Serialize(ms, xDataSet)
xmlDocument.Load(CType(ms, System.IO.Stream))

End Function
Nov 20 '05 #1
5 9974
The error tells me that what you are trying to load into an XMLDocument is
not well-formed XML.

Have you printed out the data that "ms" contains? Also, you seem to be
going though excessive trouble to take the DataSet data and persist it as
xml when a DataSet has a getXML() method that will do what you want:
Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument

'....Fill your DataSet here...

'Convert the DataSet data to XML and load it into the
XMLDocument
xmlDocument.Load(xDataSet.GetXML())
End Function

"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Hello,

I am trying to create a xmlDocument from as dataset. My code is listed
below. All seems to go well until
xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the
following error "The Root Element is Missing" ... any help would be
appreciated.

Thanks,
Rob Panosh

Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument
Dim ms As New System.IO.MemoryStream ' = Nothing
Dim ser As System.Xml.Serialization.XmlSerializer
Dim t As System.Type

t = GetType(System.Data.DataSet)
ser = New System.Xml.Serialization.XmlSerializer(t) '
System.Type.GetType("System.Data.DataSet"))

'Filled with data adapter.
Me.Execute(xDataSet, "test")

ser.Serialize(ms, xDataSet)
xmlDocument.Load(CType(ms, System.IO.Stream))

End Function

Nov 20 '05 #2
Scott,

I am trying to get a xmlDocument that can easily be manipulated at runtime.

Rob

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
The error tells me that what you are trying to load into an XMLDocument is
not well-formed XML.

Have you printed out the data that "ms" contains? Also, you seem to be
going though excessive trouble to take the DataSet data and persist it as
xml when a DataSet has a getXML() method that will do what you want:
Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument

'....Fill your DataSet here...

'Convert the DataSet data to XML and load it into the
XMLDocument
xmlDocument.Load(xDataSet.GetXML())
End Function

"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Hello,

I am trying to create a xmlDocument from as dataset. My code is listed
below. All seems to go well until
xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the
following error "The Root Element is Missing" ... any help would be
appreciated.

Thanks,
Rob Panosh

Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument
Dim ms As New System.IO.MemoryStream ' = Nothing
Dim ser As System.Xml.Serialization.XmlSerializer
Dim t As System.Type

t = GetType(System.Data.DataSet)
ser = New System.Xml.Serialization.XmlSerializer(t) '
System.Type.GetType("System.Data.DataSet"))

'Filled with data adapter.
Me.Execute(xDataSet, "test")

ser.Serialize(ms, xDataSet)
xmlDocument.Load(CType(ms, System.IO.Stream))

End Function


Nov 20 '05 #3
Cor
Hi Rob,

If you want an simple approach, create your dataset using the designer to
make an XSD, that is the most easy method you can reference to that when you
create your new dataset in your program.

If you want you can also create it in code(not that difficult).

Than you can do a mydataset.writexml(path) and readxml and you have your
dateset.

Know that there are a lot of overloaded functions with datasets and
datatables.

So there is not always one way.

I hope this gives some idea's?

Cor
Nov 20 '05 #4
Cor,

Yes that is true .... I was trying to avoid writing a file to disk. I have
it all sorted out.

Thanks for your input.

Rob

"Cor" <no*@non.com> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl...
Hi Rob,

If you want an simple approach, create your dataset using the designer to
make an XSD, that is the most easy method you can reference to that when you create your new dataset in your program.

If you want you can also create it in code(not that difficult).

Than you can do a mydataset.writexml(path) and readxml and you have your
dateset.

Know that there are a lot of overloaded functions with datasets and
datatables.

So there is not always one way.

I hope this gives some idea's?

Cor

Nov 20 '05 #5
The code I gave will give you your XMLDocument without the whole trouble of
setting up the stream and serializing.
"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:u7**************@TK2MSFTNGP09.phx.gbl...
Scott,

I am trying to get a xmlDocument that can easily be manipulated at runtime.
Rob

"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
The error tells me that what you are trying to load into an XMLDocument is not well-formed XML.

Have you printed out the data that "ms" contains? Also, you seem to be
going though excessive trouble to take the DataSet data and persist it as xml when a DataSet has a getXML() method that will do what you want:
Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument

'....Fill your DataSet here...

'Convert the DataSet data to XML and load it into the
XMLDocument
xmlDocument.Load(xDataSet.GetXML())
End Function

"Rob Panosh" <ro************************@asdsoftadfdware.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Hello,

I am trying to create a xmlDocument from as dataset. My code is listed
below. All seems to go well until
xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the
following error "The Root Element is Missing" ... any help would be
appreciated.

Thanks,
Rob Panosh

Public Function GetXMLDocument() As System.String
Dim xDataSet As New System.Data.DataSet
Dim xmlDocument As New System.Xml.XmlDocument
Dim ms As New System.IO.MemoryStream ' = Nothing
Dim ser As System.Xml.Serialization.XmlSerializer
Dim t As System.Type

t = GetType(System.Data.DataSet)
ser = New System.Xml.Serialization.XmlSerializer(t) '
System.Type.GetType("System.Data.DataSet"))

'Filled with data adapter.
Me.Execute(xDataSet, "test")

ser.Serialize(ms, xDataSet)
xmlDocument.Load(CType(ms, System.IO.Stream))

End Function



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matt M | last post: by
6 posts views Thread by Yechezkal Gutfreund | last post: by
3 posts views Thread by Tom Vukovich | last post: by
1 post views Thread by M. Posseth | last post: by
7 posts views Thread by =?Utf-8?B?ZG91Zw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.