Okay, this one's been bugging me for a few hours and I can't figure out
what to do about it. I've been working on a little project for work
that will take an RSS feed, extract certain items from it, and display
them on a webpage. Simple enough, right? Quite, except for the fact
that one of the items that needs to be displayed is a date, which is
stored in the format yyyy-MM-dd hh:mm:ss.f, and they want it displayed
nicely as MMMM dd yyyy or something like that. Easy enough, right?
So I wrote a little C# to convert the date to something nice. Here's my
code in full:
protected Xml xml;
private void Page_Load(object sender, System.EventArgs e)
{
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.Document.NameTable);
nsmgr.AddNamespace("event","http://www.acs.rutgers.edu:8888/calendar/FeaturedEventRSS#");
XmlNodeList
XmlNodeList nodeList =
xml.Document.SelectNodes("//*/event:startDateTime",nsmgr);
for(int i = 0; i < nodeList.Count; i++)
{
nodeList[i].InnerText =
XmlConvert.ToDateTime(nodeList[i].InnerText.Replace("
","T").Substring(0,19)).ToString("MMMM dd yyyy h:mm:ss");
}
}
The method that does the actual work isn't the prettiest thing ever,
but it gets the job done. However, for whatever reason, this code
snippet causes something very unusual to happen. The XML control on the
..aspx page will perform the transform as requested, but it prepends the
entire contents of the XML file in question, but without tags and
showing the effects of the code snippet above. This indicates to me
that for some reason the XML file is being duplicated and processed
twice, first without the XSL transform and then with.
What's odd about the whole thing is that I also put together a sample
identical to the one above, but without the XmlNamespaceManager, to
test on an XML file without namespaces (the file that I'm being
provided with for the actual implementation does have namespaces, as
you can see above), and it does NOT exhibit that behavior there. Could
the namespace manager somehow be causing this? If so, can anyone shed
some light on this, or at least suggest a workaround?
--
Edmund Rhudy