Parsing XML from database fields

  • Thread starter Thread starter Kent Ogletree
  • Start date Start date
K

Kent Ogletree

I am converting an app from JavaScript ASP pages to ASP.NET in VB and have
not found a good reference for the XML classes in .NET as of yet. What I
have is XML encoded data in a field in my database which I have to parse and
use to determine what controls to place on the web form. This data is placed
in the database by a separate app that we do not control, so we must deal
with what is there.

<qMultipleChoice>
<qText>What workstation are you working at?</qText>
<qChoice>1</qChoice>
<qChoice>2</qChoice>
<qChoice>3</qChoice>
<qChoice>4</qChoice>
<qChoice>5</qChoice>
<qChoice>7</qChoice>
<qChoice>8</qChoice>
<qChoice>9</qChoice>
<qChoice>Other</qChoice>
</qMultipleChoice>

The original app used MSXML to convert this, which I have personally never
used. I do not want to waste a bunch of time trying to rewrite the server
side JavaScript implementation to VB using MSXML COM if there is something
within the System.XML classes that will do the trick. Can someone make a
suggestion on what classes would be best and easiest to use here and where I
can find some good help to get started with it?

TIA,
Kent
 
See the System.Xml XmlDocument, XPathDocument and XmlTextReader classes. The
XmlDocument encapsulates a DOM-based approach which you'll find will be the
closest to the MSXML DOMDocument code in the existing JavaScript ASP page.
The XPathDocument class also uses a DOM model, but is read-only, and
optimized for fast XPath queries. The XmlTextReader is a forward-only node
reader that is extremely fast when you only need to move through a document
from start to end retrieving data. Very generally, if you need to make
modifications to a document in code, use an XmlDocument. When you don't need
to make changes, but you do need to query the document repeatedly, use an
XPathDocument. When you don't need to make changes and you only need to
extract data from a document once, or the document is large, and you don't
want to keep it in memory, use an XmlTextReader.

Finally, when your data is regular (such as table data from a database), you
can use an XmlDataDocument, which you can transparently convert to a Dataset
(and back again), which you might find convenient.

In your case, if you're using the XML-formatted question simply to populate
question objects or create controls for your page, the XmlTextReader is
probably the best way to go.
 
Back
Top