Can you insert elements into an XML file that exists as a string?

P

pat

Given:

Dim r As String = WS.getInfo("arg1", "arg2", "arg3")
Dim dsTest As New DataSet
Dim srTest As New System.IO.StringReader(r)
dsTest.ReadXml(srTest)

This is how I currently populate a DataSet. The web service "WS"
returns a single string, within which is an XML document. It works
great.

There is a problem, though, in that the XML has missing elements
sometimes. On the server, when a database column is NULL, the server
simply doesn't send it. This is causing my VB.NET app to halt
(apprently waiting for the element tags that won't be arriving)
indefinitely. This happens whether schema is infered or
pre-determined-as one would expect.

So what is needed is 2-fold:

1. Determine if there is a missing element, and ..
2. Insert an empty element in its place (<thing></thing>).

Considering I'm loading the XML as a string, what is the best approach
for this?

TIA!

pat
:)
 
C

Cor Ligthert [MVP]

Pat,

Afaik is the most simple solution in this, putting the schema in the dataset
as you write it.
dstest.WriteXml(sw, XmlWriteMode.WriteSchema)

I hope this helps,

Cor
 
P

pat

Cor,

Thanks for the reply! I found the best fix to be at the source, rather
than dealing with the output on the client. Parsing inbound XML for
missing tags would have been too task intensive!

Your idea does highlight my next problem, which is how to load schema
from anywhere but a .xsd file. I need the running version of the
software to NOT have a bunch of .xsd files laying around for folks to
mess with!

I'll post another thread for that question.

Thanks!

pat
:)
 

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