Building XML in VB.NET

S

Scott Lyon

Quick question for you guys:

First, let me tell you that I'm new to VB.NET (I've been programming VB6/ASP
for years), so bear that in mind.

I'm working on an application that needs to build XML based on data from a
stored procedure (or procedures, as it may require multiple procedures), and
needs to pass that XML as a string to a Web Service.


Am I better off creating this XML using the XMLDOM that I've used in VB6, or
is there a better/easier way to generate custom XML in VB.NET?


At first I thought I could just dump a DataSet to XML using the WriteXML
method, but at first glance it seems that writes it to a file, and I'd
rather avoid the step of writing to a file, and then having to read it back
into memory again to pass it to the Web Service. Not only that, but the XML
I need to create is rather complex, with elements within elements within
elements, and I've been unable to create the parent/child relationships
between the elements.

Then I thought I could use the XMLTextWriter class, but that too seems to
write only to a file.


Ideas/suggestions?


Thanks!
 
J

Jared

You can use a stream object to write the xml, you will have to add any
datarelation, constraints, etc. to get the relational structure you want.
Either way, it's probably a stream object that you'll need to research to
produce the results you want. If you are using one of your own webservices
create an "overloaded" method that accepts a dataset or an xmldocument
object - use the messagename attribute.

Dim sw As New System.IO.StringWriter
ds.WriteXml(sw, XmlWriteMode.IgnoreSchema)
sw.Flush()
Dim MyStr As String = sw.ToString
sw.Close()
MyService.MyMethod(myStr)

Jared
 
M

Mary Chipman

Have you tried the XML functionality in SQL Server? Perhaps your
stored procedures could output it in the correct format? There's an
entire book on XML and Internet support in SQL Books Online.

--Mary
 
J

Jared

You can use a stream object to write the xml, you will have to add any
datarelation, constraints, etc. to get the relational structure you want.
Either way, it's probably a stream object that you'll need to research to
produce the results you want. If you are using one of your own webservices
create an "overloaded" method that accepts a dataset or an xmldocument
object - use the messagename attribute.

Dim sw As New System.IO.StringWriter
ds.WriteXml(sw, XmlWriteMode.IgnoreSchema)
sw.Flush()
Dim MyStr As String = sw.ToString
sw.Close()
MyService.MyMethod(myStr)

Jared
 
C

Cor Ligthert

Scott,

The documentation on MSDN is in my opinion a little bit confusing when it
goes about writing a dataset as XML file.

dataset.WriteXML(path) does completly the job.

I hope this helps

Cor
 

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