[quoted text, click to view] "jvr" <nospam@devdex.com> wrote in message news:ecMEP2XIFHA.3664@TK2MSFTNGP10.phx.gbl...
> So I was wondering whether I could change the way in which the xml was
> obtained from the ADO.NET dataset, at present I use getXML().
There's no secret switch to set that would make ADO.NET write out an ambiguous
date/time, if that's what you're asking. :-)
WriteXml( ) is considerably more flexible than GetXml( ), though. You'll need
to inject either an XSLT stylesheet to transform the date/times, or an XmlText-
Writer that reformats date/times. In either situation, choosing GetXml( ) over
WriteXml( ) makes that migratory stage more cumbersome than it should be.
For example, suppose you have one column named SalesDate that maps to an
XML element. You could use the following XmlTextWriter to control how the
content of this field gets written,
public class DateFormatXmlTextWriter : XmlTextWriter
{
private string watchElement;
private string dateFmtSpec
private bool onWatch;
public DateFormatXmlTextWriter( TextWriter writer, string watchElement, string dateFormat)
: base( writer)
{
this.watchElement = watchElement;
this.dateFmtSpec = dateFormat;
}
public override void WriteStartElement( string prefix, string localName, string ns) {
base.WriteStartElement( prefix, localName, ns);
if ( 0 == string.Compare( this.watchElement, localName))
onWatch = true;
}
public override void WriteString( string text)
{
if ( onWatch ) {
try {
DateTime dt = DateTime.Parse( text);
text = dt.ToString( this.dateFmtSpec);
} catch ( FormatException ) { ; }
onWatch = false;
}
base.WriteString( text);
}
}
Then you would call WriteXml( ) pass an instance of this specialized XmlTextWriter
wrapped around your System.IO.StringWriter, the name of the element to watch for,
the date/time format to translate into, and XmlWriteMode.IgnoreSchema.
myDataSet1.WriteXml(
new DateFormatXmlTextWriter( myStringWriter, "SalesDate", "yyyy-MM-ddTHH:mm:ss"),
XmlWriteMode.IgnoreSchema
);
If you're calling GetXml( ) you just won't have this kind of flexibility.
Derek Harmon