Visit Our Home Page
 Explored,Designed,Delivered.sm
Welcome, Guest. Please Login or Register (Password Reminder)


Creativyst Forums 
Support & Discussion 
Register Help Search Login  
   
   Creativyst Forums-TOP
   Web Site Design
   XML (w/ Attributes) Binding To HTML
(Moderator: admin)
 Author
Topic: XML (w/ Attributes) Binding To HTML       [Link=23]
Reply Please log in first.
dmichener
New Member


Posts: 2




     
    XML (w/ Attributes) Binding To HTML   (Date posted: 09/25/02 at 10:48:23) Quote Modify Delete

I have an XML doc that has leaf nodes with attribute values. When I attempt to bind and display the values of that node IE displays a blank. If I remove the attribute from the node, IE displays the data fine.

In the following sample, the description text does not display. If you remove the fmt='A' from the description leaf node, then it does display.

Thanks,
-Dave

XML:
<test>
<keycode>Big Val</keycode>
<description fmt="A">Big Desc</description>
</test>

HTML:
<html>
<body>
<xml id="dsoWF" src="tst.xml"></xml>
<TABLE WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1 >
<TR>
<TD>KeyCode</TD>
<TD><div DATASRC="#dsoWF" datafld="keycode"></TD>
</TR>
<TR>
<TD>Desc</TD>
<TD><div DATASRC="#dsoWF" datafld="description"></TD>
</TR>
</TABLE>
</body>
</html>

   E-Mail   Ip: Logged
JRepici
Administrator


Posts: 328





Gender:
      JohnRHere2
    Re: XML (w/ Attributes) Binding To HTML   (Date posted: 08/08/03 at 21:58:28) Quote Modify Delete

Dave,

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:
    • <description>
          <fmt>A</fmt>
          Big Desc
      </description>

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:

     <test>
         <keycode>Big Val</keycode>
         <description>
             <fmt>A</fmt>
             <$TEXT>Big Desc</$TEXT>
         </description>
     </test>

One way to display it is located here in a test page I've set up. Here's the actual html for that

<html>
<body>
<xml id="dsoWF" src="tst.xml"></xml>
<TABLE WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1 >

<TR>
<TD>KeyCode</TD>
<TD>
    <div DATASRC="#dsoWF" datafld="keycode"></div>
</TD>
</TR>

<TR>
<TD>Desc</TD>
<TD>
     <TABLE DATASRC="#dsoWF" DATAFLD="description"
     BORDER=0 CELLSPACING=0 CELLPADDING=0>
    <TR>
    <TD>
         <SPAN DATASRC="#dsoWF" datafld="$TEXT"></SPAN>
         (fmt=<SPAN DATASRC="#dsoWF" datafld="fmt"></SPAN>)
     </TD>
     </TR>
     </TABLE>

</TD>
</TR>

</TABLE>
</body>
</html>

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?

     -John

Last modification: JRepici - 08/08/03 at 21:58:28

   E-Mail   Ip: Logged
dmichener
New Member


Posts: 2




     
    Re: XML (w/ Attributes) Binding To HTML   (Date posted: 09/26/02 at 13:58:41) Quote Modify Delete

John,
Thanks for the quick response. I wasn't able to find this info anywhere else!

The particular usage in our system where this field will be used will always have attributes. However, what it does have is multiple attributes for that node (none of which need to be displayed). From your description provided here, I think that shouldn't matter.

Thanks again,
-Dave

   E-Mail   Ip: Logged
JRepici
Administrator


Posts: 328





Gender:
      JohnRHere2
    Re: XML (w/ Attributes) Binding To HTML   (Date posted: 09/29/02 at 14:54:07) Quote Modify Delete

Dave,

Glad to be of service.

I probably should have included a bibliography with the article for you. Learning...

Let me know how the project turned out when its done.

       -John

   E-Mail   Ip: Logged
Reply Please log in first.
Pages: 1
Jump to:

YaBB Board c 2000
YaBB Programming Team
 



















© Copyright 2002 - 2008 Creativyst, Inc.