Home All Groups Group Topic Archive Search About

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

Author
9 Mar 2006 10:30 PM
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
Show quoteHide quote
:)

Author
10 Mar 2006 7:29 AM
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
Author
11 Mar 2006 12:51 PM
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
:)

Cor Ligthert [MVP] wrote:
Show quoteHide quote
> 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