This is a good question because it shows some of the underlying workings of Microsoft's databinding scheme in very simple terms. Also, this is not well covered in the article.
1. In databinding, when an element contains an attribute, the attribute is considered a sub-element of that element,
- So this:
- <description fmt="A">Big Desc</description>
- Becomes this:
therefore, you must display this element as a nested record set, not as a single data field.
That leads us to another problem...
2. In databinding there are fields and there are hierarchical (nested) recordsets.
An element that is a field may contain only character data, NOT child elements. If an element contains child elements it is a nested record set.
How do we display plain text that is included along with the field elements in a record set? Use the special name $TEXT to refer to the text within the recordset element.
Conceptually then, for the sake of databinding your xml file looks like this:
One way to display it is located here in a test page I've set up. Here's the actual html for that
<xml id="dsoWF" src="tst.xml"></xml>
<TABLE WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1 >
<div DATASRC="#dsoWF" datafld="keycode"></div>
<TABLE DATASRC="#dsoWF" DATAFLD="description"
BORDER=0 CELLSPACING=0 CELLPADDING=0>
<SPAN DATASRC="#dsoWF" datafld="$TEXT"></SPAN>
(fmt=<SPAN DATASRC="#dsoWF" datafld="fmt"></SPAN>)
There's still one more possible problem here which I've not had time to investigate. The problem comes if the attribute in your xml file is optional. This code does not display the data when the fmt attribute is not there.
This is required in many XML files and so I'm eventually going to have to learn how it's done. If you have time Dave, and come up with an answer to this behavior, please let me know what you find. Does your current project require the attribute to be optional?
Last modification: JRepici - 08/08/03 at 21:58:28