Export (0) Print
Expand All

All About Data

As of December 2011, this topic has been archived. As a result, it is no longer actively maintained. For more information, see Archived Content. For information, recommendations, and guidance regarding the current version of Internet Explorer, see Internet Explorer Developer Center.

Tom Moran
Rafael M. Muñoz
Microsoft Corporation

March 6, 2000


A nest of CDATAs - Storing data in multiple CDATA sections
Pondering the big move - Transferring Outlook Express files to another machine
Please parse the Access, would ya? - Creating an XML-parsable string from a database

The Web Men Talking Award - Beyond the Basics
The Web Men in Short

Eventually, it comes down to information: how to get it, store it, move it around. The Web Men take on these issues in their answers this month, addressing data storage in two very different ways, and the transfer of Outlook Express files from one machine to another. And while Kusuma is on another project this month, Tom and Rafael announce the newest winner of the Web Men Talking Award. Read on.

A nest of CDATAs

Dear Web Men:

I've got a dilemma. We've decided to build our own Session object to maintain session state between pages in our Web "farm." (I dislike that term; it doesn't grow anything, and there are no cows.)  Our Session object is coded in Visual Basic® 6.0 and uses SQL Server 7.0 (or any ODBC database) to store session data between page requests.  The object is instantiated at the beginning of every page we need it on, and destroyed at the end of those pages.

We've got it implemented so that it is supporting storage of strings, numeric data types, arrays, etc. (but not objects—we can live without that).  The session elements (variables) are stored in a single field in SQL Server in an XML structure.  So each variable in the Session object is stored in its own cute little tags, depending on its data type, etc.

Our problem arises from the need to store an XML document (in the form of a string) in a Session variable.  Obviously, there were problems with this. We were wrapping our data in CDATA sections to preserve its integrity (whatever you passed in is what you got out).  But the XML document that I want to store in the Session variable already contains a CDATA section—and, according to the MSXMLDOM documentation, CDATA sections cannot be nested.

Do you have any suggestions?


Greg Cymbala

The Web Men reply:

The first approach that came to mind was to use the ASP Server.URLEncode() method to encode the XML document that you want to store, then decode it when you retrieve the XML document. That way, you could wrap the encoded XML document in a CDATA tag and avoid the nesting problem. For example:

<![CDATA[ some data... ]]>

would not be parsed because it would be encoded as:


Unfortunately, the ASP Server.URLEncode() method does not have a counterpart for decoding the encoded CDATA tag. So it is not useful for what you are trying to do.  "Great – thanks for the help," you say. Patience, friend—we'll get there. But before we answer the question you asked, we have a couple of comments.

We don't know exactly what your requirements are, but it strikes us as somewhat unnecessary to store the XML in a CDATA section at all. Keep in mind that CDATA doesn't preserve data integrity; it simply allows you more flexibility in allowed characters. There are other ways to do this, which we'll leave as an exercise to the readers (please use the commenting feature if you have a good idea;  for some hints, look at the text method of IXMLDOMNode).

Now to answer your question:  You can both encode and decode an XML document using the JScript® escape() and unescape() methods. Shown below is a sample HTML document that encodes and decodes a CDATA string using those JScript methods.

<TITLE>Encode/Decode CDATA</TITLE>
    var sCDATA = "<![CDATA[ some data... ]]>";
    function encodeCDATA(cdata)
        return escape(cdata);
    function decodeCDATA(cdata)
        return unescape(cdata);
<BODY STYLE="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10pt">
<H3>Encode/Decode CDATA</H3>

This approach can be used to handle multiple levels of nested CDATA simply by encoding each level before wrapping it in a CDATA tag. Note that each level must be decoded individually in order to retrieve the original XML data.

Once you've used the above code, you can see an example of how the inner-most CDATA level might appear when repeatedly encoded by pressing the Encode CDATA button in the above example HTML page several times without pressing the Decode CDATA button in between. Later, to retrieve the original XML data, simply press the Decode CDATA button repeatedly until each level of encoding has been decoded.

Pondering the big move

Dear Web Men:

I know the answer to this must be somewhere, but I can't find it.

I bought a new computer and now would like to transfer my e-mail with all its folders from the old one to the new one.  I have Outlook Express 5 on both systems. 

Can you please help me?

Thanks very much,

Jane Lucas

The Web Men reply:

We were just talking about this the other day—really. Walking back with our lattes in hand, we looked to the sky and pondered how our readers were going to keep from losing their e-mails with everyone moving to newer and faster computers. Follow along and you shouldn't lose a step in contacting us through e-mail with your next question!

Outlook Express Non-MSDN Online link uses two file types, MBX and IDX, to store your messages on your machine. For instance, you would find an inbox.mbx and outbox.mbx on your system where your e-mail messages exist, along with corresponding IDX files. Should you create additional folders to better organize your mail, Outlook Express will actually create two files, "folderX.mbx" and "folderX.idx."  The first file is where the actual messages will be stored; the latter contains indexing information for all the messages that will be stored in the new folder.  The "X" is an ordinal number, which corresponds to the folder creation order—for example, our first folder created would be folder1.mbx, then folder2.mbx and so on; each with its corresponding IDX file.

Normally, these files are kept in the installation directory; for users of Windows NT®:

C:\Winnt\Profiles\"user name"\Application Data\Microsoft\Outlook Express\Mail

and for users of Windows 95 or Windows 98:

C:\Program Files\Outlook Express\"username"\mail

If the file isn't in that location, it may have been installed in another area.  In that case, simply use the Tools menu in the Windows Explorer to find the file.

There is also one other file kept in the directory above: folders.nch, which maintains a record of all the folders and an index that associates the .mbx and .idx files with the friendly names of their corresponding folders. For example, when you create that first folder called "Saved Mails From 1999," the NCH file associates the MBX and IDX files for "folder1" with the name you've given the folder. Had enough information yet? Hey, details are important!

Now how do we move mail from one machine to the other?  We simply copy all the MBX and IDX files and the single NCH file from our old machine to the installation location on the new machine. Our new machine will already have an NCH file and corresponding MBX and IDX files for Inbox and Outbox, but we will just copy right over them.

Two great Knowledge Base references are:

Please parse the Access, would ya?

Dear Web Men:

I am a Web Programmer/Analyst. I have a problem. I need to access a small Access 97 database to retrieve information in an XML parsable format using Visual Basic 6.0. Is this possible?  I don't know a lot of Visual Basic, but I do know some. Can you all help me or at least point me in the right direction?

Thanks in advance,

Quinton Wilkerson

The Web Men reply:

We've got problems, too, buddy. But luckily, we can do something about yours. Given inclusion of the phrase "XML parsable" in your question, it sounds like you want to create an XML document file containing tagged data elements, or a string containing such elements, rather than simply an in-memory XML document whose nodes you could manipulate programmatically. Our answer: Yes, data can be retrieved from an Access 97 database and converted to an XML parsable format using Visual Basic 6.0.

There are two approaches you can take for creating information in an XML parsable format:

  • Create an in-memory XML document containing data from the Access 97 database, and then save the in-memory XML document to a file by either retrieving the value of the "xml" property of the in-memory XML document or formatting the XML using XSL
  • Simply create the XML tagged data elements on the fly as you retrieve data from the Access database. The latter method is not as useful for larger data sets.

The first method requires some understanding of how to manipulate XML document nodes for an in-memory XML document. For what you are trying to accomplish, this may not be necessary.

The code below shows an example of the second method. A string containing a complete XML document is created from an Access 97 database containing team scheduling data (can you tell we work in support?). Note that the following code example relies on an ODBC System DSN named "Schedule" for the server-side Access database.

Private Function createXML() As String
    Dim sXML As String
    sXML = "<?XML VERSION=""1.0"" ENCODING=""UTF-8""?>" & vbCrLf

    Set Conn = CreateObject("ADODB.Connection")
    Conn.Open "Schedule"
    Set Schedule = Conn.Execute("Select * from Schedule")
    Do While Not Schedule.EOF
        sXML = sXML + "<SCHEDULEITEM>" & vbCrLf
        sXML = sXML + "<SLOTDATETIME>" & Schedule("SlotDateTime") & "</SLOTDATETIME>" & vbCrLf
        sXML = sXML + "<SLOTSEQ>" & Schedule("SlotSeq") & "</SLOTSEQ>" & vbCrLf
        sXML = sXML + "<MEMBERALIAS>" & Schedule("Alias") & "</MEMBERALIAS>" & vbCrLf
        sXML = sXML + "</SCHEDULEITEM>" & vbCrLf
   sXML = sXML + "</TEAMSCHEDULE>" + vbCrLf
   createXML = sXML
End Function

The resulting string will look like the following XML document:

   <SLOTDATETIME>05/04/1998 7:00:00 AM</SLOTDATETIME>
    <SLOTDATETIME>05/04/1998 8:00:00 AM</SLOTDATETIME>
    <SLOTDATETIME>05/04/1998 9:00:00 AM</SLOTDATETIME>

This string can be passed to an XML runtime object for parsing through the loadXML() method, or it can be saved to a file for later parsing through the XML runtime object load() method.

The Web Men in Short

Q: Josh Bell wants to make a <DIV> show up over an <IFRAME> or select box.

A: See our archived answer Where there's a will, there's a display.

Q: Gerald Whittington wants to implement security on his intranet.

A: Refer to Securing Your Web Application for more information.

Q: Taras Tielkes asks, "Is the Java 'treeview' applet from the MSDN Online library available in a reusable and/or source form?"

A: Unfortunately, it is not—but you can find some equivalent applets on the Web.

Q: Mary Jackson wants to validate customer e-mail addresses.

A: Check out HexValidEmail Non-MS link  by Hexillion Technologies Non-MS link.

Q: Ray Gardner wants information on integrating Microsoft Office applications with IIS.

A: See Automation With Internet Scripting Non-MSDN Online link.

Q: Samson Marsh wants to share JavaScript routines across several HTML pages.

A: Create a file with all your script, and call it something like sharedScripts.js.Then insert <SCRIPT src="sharedScripts.js"></SCRIPT> on each page to access the script.

Q: John O'Connell wants to use FrontPage 2000 to set up a database connection.

A: Refer to the Microsoft KB article "FP2000: ASP Web Wizard 2000 for Databases Available for Download." Non-MSDN Online link

Rafael M. Muñoz, when not playing or coaching his favorite pastime (volleyball), provides technical assistance as a full-time developer support engineer for Microsoft Developer Support.

Thomas Moran, when not struggling to maintain some semblance of sanity (working with Rafael certainly doesn't help), toils with a prodigious team that creates articles and other content from Microsoft's Developer Support.

© 2014 Microsoft