XML data binding with data types
By Chris Curry
Requirements: IE 5.0 or greater
If you are a developer who is hooked on XML (like me), at one time or another you’ve probably wanted to offer a means for your application users to edit your XML documents directly. If you’ve done this via a web-based interface then you’ve probably come across Microsoft’s XML DSO, or Data Source Object. The
DSO for XML offers developers a relatively simple and efficient method for binding XML data directly to HTML elements using a
XML data island.
Here are some examples of what I feel are some interesting and
potentially very powerful features utilizing the Microsoft XML DSO and data types within IE 5 and
greater.
First take some typical XML that may have originated from a
database, file, etc. I've put together a simple XML data island which may be
construed as payment history from various customers.
Sample XML #1
<xml id="MyXML1">
<customers>
<customer>
<name>Arbit Enterprises</name>
<account>101</account>
<payment>2012.5</payment>
<date>2000-01-01</date>
</customer>
<customer>
<name>Chris's Widgets</name>
<account>210</account>
<payment>502.46</payment>
<date>2000-03-23T05:31:00</date>
</customer>
<customer>
<name>Sanford & Son</name>
<account>345</account>
<payment>.40000</payment>
<date>1999-11-13</date>
</customer>
<customer>
<name>Craig's Data Warehousing</name>
<account>780</account>
<payment>30000</payment>
<date>2000-05-10T14:45:34</date>
</customer>
<customer>
<name>Rosa's wheels</name>
<account>510</account>
<payment>6789.23</payment>
<date>2000-04-30</date>
</customer>
</customers>
</xml>
From scanning this XML one can see there are various nodes which contain character data, number data, and date data.
Here you have the data island bound to a table.
Arbit Enterprises
101
2012.5
2000-01-01
Chris's Widgets
210
502.46
2000-03-23T05:31:00
Sanford & Son
345
.40000
1999-11-13
Craig's Data Warehousing
780
30000
2000-05-10T14:45:34
Rosa's wheels
510
6789.23
2000-04-30
Sample Bound Table #1
| Customer |
Account# |
Payment |
Date |
|
|
|
|
View XML Data View Source
Basically it's what you see is what you get. Your numbers and the ISO formatted dates are just strings to the data island's DSO even though they probably came from a database where they were indeed explicitly typed.
This becomes even more apparent when you bind the XML to a user interface as shown in the example below. Sample Bound User Interface #1
View XML Data View Source
In this interface the user can type whatever values they want and the XML structure will allow it. You can see the XML being updated in "Sample Bound Table #1" or you can click "View XML Data" to view the underlying XML.
Under this design your ISO formatted dates that you were using to conform to standards as well as make it easy to sort and process your XML have now become a big eye sore to your user. Not to mention that since there isn't any validation, every field except perhaps the customer "name" field is prone to entry error and failure if this data is sent back to a database.
|