About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 35 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

The simpler the problem at hand, the more people think they're experts in it.

Asa Dotzler



Navigation





<April 2025>
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 4/17/2025

Totals
Posts - 2657
Comments - 2678
Hits - 2,737,659

Averages
Entries/day - 0.33
Comments/entry - 1.01
Hits/day - 344

Updated every 30 minutes. Last: 7:46 AM Pacific


  09:56 PM

Since I have this-here newfangled ASP.NET 2.0 to play with, I thought I'd do something, you know, simple, just for fun. I have a list of quotations that I keep for the blog (over there on the left). At the moment, I maintain those as a text file (!); to display them, I use a stream reader to slurp them out of the text file into rows in a dataset. The show-all-quotations page uses a Repeater.

This seemed like an interesting thing to do XML-ishly. It's not that the old system had any particular flaws, but I thought I might be able to cut down on the coding by using an XmlDataSource control to read the quotations -- voilà, direct data binding! Right? Also perhaps to write out new quotes when I found them.

I read the quotes into a dataset and then used DataSet.WriteXml to create an XML file. The format looks like this:
<?xml version="1.0" standalone="yes"?>
<Quotations>
<Quotation>
<quote>A man may write at any time, if he will set himself doggedly to it.</quote>
<author>Samuel Johnson</author>
<source />
</Quotation>
<Quotation>
<quote>I have made this letter longer than usual, only because I have not had the
time to make it shorter.</quote>
<author>Blaise Pascal</author>
<source />
</Quotation>
<Quotation>
<quote>Knowledge is of two kinds. We know a subject ourselves, or we know we can
find information upon it.</quote>
<author>Samuel Johnson</author>
<source />
</Quotation>
</Quotations>
where <source> is for a URL, if any.

I created a new page and added an XmlDataSource control and a DataList control. And I could not get the DataList control to display anything. Nothing. Ever. I plugged into the ItemDataBound event and displayed the type of e.Item.DataItem, which reported itself as the mysterious XmlDataSourceNodeDescriptor. Sealed class, I read, and I couldn't figure out what to cast it to so I could look inside.

Eventually I was reduced to reading the docs[1], where I found this:
If you have an .xml file in which property values are expressed in a format other than attributes, you can create a transformation file (.xslt) that can dynamically reformat the .xml file so that it is compatible with the XmlDataSource control.
Oh, bother. Two problems. One is, you know, transformations. Blech. But transformations also have another side effect. Elsewhere in the docs it says:
There are some restrictions to the editing capabilities of the XmlDataSource:
  • The XML data must be loaded from an XML file that is indicated by the DataFile property, not from inline XML specified in the Data property.
  • No XSLT transformation can be specified in the Transform or TransformFile properties.
  • ...
Dang. But I was in it this far, so I thought I might as well finish. I borrowed the transformation out of the walkthrough and adjusted it, with much tinkering, to suit my quotations file. And presto, it (eventually) worked.

I'm not sure it's worth the effort as such. I'll need to write code to update the file (although I can do that using DataSet.WriteXml again, I suppose. But it was an interesting experiment, and another example of how, if you beat your head against something long enough, you can learn something.

[1] Ironically, I am almost certain that I wrote that topic.

[categories]   ,

[3] |