A fellow MVP asked if there is a way to dump XML content while reading it from a stream without buffering the whole XML document. Here is a scenario - an XML document being read from a HttpWebResponse stream and needs to be passed as an XmlReader to an XmlSerializer to deserialize it into objects. This works fine in a streaming way - just create an XmlReder over the stream and pass it to an XmlSerializer. But what if incoming XML needs to be logged? Of course then one could go buffer-log-process architecture, effectively killing performance and scalability. Fortunately there is a better way - by extending XmlReader one can make it dumping current node it's positioned at. Here is how.
May 2005 Archives
Continue reading Effective XML: Dumping XML content while reading it from a stream.
Hey, self-learners, did you know that you can take MIT course online for free? MIT's OpenCourseWare made it possible. That's really cool resource for self education. [Via Wesner Moise]
Enrolling in an
online computer science program can help advance your knowledge.
Altsoft N.V. has announced a relase of the Xml2PDF formatting engine version 2.3, now supporting WordML. Altsoft Xml2PDF is a .NET based formatting engine for converting various XML-based formats to PDF. It supports XSL-FO, SVG, XHTML, WordML and XML+XSLT as an input and generates PDF as an output. The prices are from $49 for the Workstation version to $1599 for the API version. Free evaluation versions are available. SourceForge has fixed the stat system and now we can analyze Mvp.Xml project statistics. The numbers are good - 8-15K hits/mo and 700-800 downloads/mo, not bad for a 1.0 release. Hibiscus blooms again at our home. Actually outdoor it blooms non stop all year here in Israel, serving as a perfect undemanding but beautiful hedge. It's everywhere, every color and every form, there are even Hibiscus trees. But my home Hibiscus blooms two or three months in a row, then rests for couple months and blooms again. Every flower lives only day or two. Short but bright life. So yesterday I passed 70-316 exam ("Developing and Implementing Windows-based Applications with Microsoft Visual C# .NET and Microsoft Visual Studio .NET"). Slack preparation during a week, bad-surprizingly too many questions on darned DataSets, but anyway I got 900 out of 1000. Now that I passed these three exams (70-315, 70-316 and 70-320) I should reach MCAD certification status which I wanted. Hey, I passed 4 certification exams during last 5 months (3 for Microsoft and one for IBM) and not a single one before in my life. Should be some sort of psychological compensation effect. That was fun actually, but I better stop now. Actually I'm going to take other two exams to reach MCSD, but later, later. Now back to System.Xml v2.0, I love it already as a new car or new PC. Same feelings! Some users report that after installing Netscape 8 Internet Explorer and other IE-based browsers usch as Avant browser stop applying XSLT stylesheets, even the default stylesheet used to render XML documents. That probably has something to do with "Firefox or IE6 rendering" feature in Netscape. Beware.
If you do make your own web site design
make sure you research various web site design
firms before you invest money into a web
designer who might know less about web page design
than you do.
Jonathan Marsh, who is one of Microsoft's representatives at the W3C, an editor of XML Base, XPointer, XInclude, xml:id, some XQuery 1.0 and XPath 2.0 specs and is by the way the original author of the defaultss.xsl which is used in Internet Explorer to display XML documents, is blogging. His blog called Design By Committee. Subscribed. Well, I recently decided I need to be an MCAD. That requires to pass three exams. I passed one (70-315) in December and yesterday I went for a second one - 70-320 (Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework). Should admit Remoting, Serviced Components or COM+ aren't what I'm working with every day. Anyway $50 (I don't know why but seems like Microsoft exams are just for $50 in Israel), 43 really good questions, 2.5 hours of brains gym. Passed, 904 out of 1000. Now that I passed two core exams I need to pass one elective exam to achieve MCAD status. The question is which one? 70-229 (SQL Server 2000) would be a challenge as I'm not really a database guy. And SQL Server 2000, you know, if only it would be SQL Server 2005 then ok. 70-340 (Security) is even more challenging. The easiest (and the most interesting for me now) is 70-316 exam (Developing and Implementing Windows-based Applications with Microsoft Visual C# .NET and Microsoft Visual Studio .NET). And provided limited time that's what I'm going for next week. Yes, I know I'm a slacker and always looking for easy ways... Oh, and if you are thinking about Microsoft certification too, beware that the Free Second Shot Offer ends May 31 (one should take first exam before May 31 and if fails can retake it for free in June). Another handy feature implemented in .NET 2.0 Beta2 is that XmlReader class now implements IDisposable interface and so can be closed automatically when using with "using" statement in C#: using (XmlReader r = XmlReader.Create("../../source.xml")) { while (r.Read()) Console.WriteLine(r.NodeType); }Really handy. And implemented in literally couple of lines. It's a pity we don't have such simple but useful stuff in .NET 1.1. Dave Pawson investigates if there is enough interest in a community developed web logging system based on XSLT processing and Atom8. He welcomes any feedback. I've been using XSLT-powered online publishing systems such as Docbook Website and definitely see enough potential behind Dave's idea. .NET XSLT API is traditionally ugly. XslTransform class (obsoleted in .NET 2.0) had 8 Load() methods and 9 Transform() ones in .NET 1.0. In .NET 1.1 - 11 Load() methods (5 of them obsoleted) and 18 Transform() (9 obsoleted). Huge mess. Brand new XslCompiledTransform in .NET 2.0 Beta2 has just 6 Load() methods and 14 Transform() ones, none obsoleted so far. Sounds good, but does this pile of method overloads cover all usage cases? Unfortunately not.
Continue reading .NET XSLT API - broken again?.
This one little improvement in System.Xml 2.0 Beta2 is sooo cool anyway: XPathNodeIterator class at last implements IEnumerable! Such unification with .NET iteration model means we can finally iterate over nodes in an XPath selection using standard foreach statement: XmlDocument doc = new XmlDocument(); doc.Load("orders.xml"); XPathNavigator nav = doc.CreateNavigator(); foreach (XPathNavigator node in nav.Select("/orders/order")) Console.WriteLine(node.Value);Compare this to what we have to write in .NET 1.X: XmlDocument doc = new XmlDocument(); doc.Load("../../source.xml"); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator ni = nav.Select("/orders/order"); while (ni.MoveNext()) Console.WriteLine(ni.Current.Value);Needless to say - that's the case when just a dozen lines of code can radically simplify a class's usage and improve overall developer's productivity. How come this wasn't done in .NET 1.1 I have no idea. And how come the MSDN documentation for the class still doesn't mention this cool feature - I have no idea either. More security changes made in XSLT in .NET 2.0 Beta2. When working with XslCompiledTransform class: document() function is disabled by default. To enable it, one has to provide XsltSettings enum value with EnableDocumentFunction field set to the XslCompiledTransform.Load() method: XslCompiledTransform xslt = new XslCompiledTransform(); XsltSettings settings = new XsltSettings(); settings.EnableDocumentFunction = true; xslt.Load("style.xslt", settings, new XmlUrlResolver());or XslCompiledTransform xslt = new XslCompiledTransform(); XsltSettings settings = new XsltSettings(true, false); xslt.Load("style.xslt", settings, new XmlUrlResolver());(first argument in the XsltSettings constructor controls document() function enabling). Or even (for full trusted stylesheets): XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("style.xslt", XsltSettings.TrustedXslt, new XmlUrlResolver());Note, that then one must provide an instance of XmlResolver class to the XslCompiledTransform.Load() method. It' used to resolve stylesheet URI and xsl:include/xsl:import statements and somehow cannot be null, so there doesn't seem to be any way to disable xsl:include/xsl:import, despite the documentation claims xsl:include/xsl:import are enabled by default. Weird. And even if at compile time the document() function was enabled, one can supress it provideing null as a XmlResolver to the XslCompiledTransform.Transform() method. And btw, there is only one Transform() overload, which accepts XmlResolver, which is also weird, because it requires XmlReader and what if I've got IXPathNavigable as a source XML? Script blocks are disabled by default too. Use the same XsltSettings enum to enable it. I had a conversation with somebody about how EXSLT.NET worked around the hyphenated EXSLT function names problem and if there are better ways to solve it. Here is a suggestion for Microsoft: give us more control over exposing .NET methods as extension functions and make it declarative.
Continue reading Declarative way to expose methods as XSLT extension functions?.
Yep, no DTD is allowed by default in the .NET 2.0 Beta2: XmlReaderSettings.ProhibitDtd Property (System.Xml) That's for sure contradicts "Allow all XML syntax" gospel, but looks like Microsoft takes security very seriously nowadays. Well, at least Microsoft's XML team. Most likely that was a hard decision, but may be not since what are the options here in the face of the billions of laughs attack? If 1Kb well-formed XML document can hog all your CPU and memory when you just open it in a browser, which processes DTD, such as IE? Well, sure it's just a default value and can be changed. But defaults are more than just defaults and I bet most .NET 2.0 applications won't accept XML with DTD. That's sort of a milestone in XML history. Can one change a value of a variable in XSLT? Unexpected answer - yes, when debugging XSLT in Visual Studio 2005 Beta2. I'm not sure even if it's a bug. Actually it can be quite useful when debugging to be able to change some values, right? Do other XSLT debuggers allow it? I'm learning new XML stuff in Visual Studio 2005 Beta2. So far I'm still overwhelmed! New System.Xml is sooooo cool, elegant and professional, kudos to the WebData team, this is really a piece of programming art. Still I filed 4 bugs so far in just one hour. Finally something interesting from the Channel 9: Ken Levy shows new cool XML tools in Visual Studio 2005 - improved XML editor, XML Intellisense, schemas, XML code snippets, XSLT editing and debugging etc etc etc. 41 min video, still worth watching. On behalf of the Mvp.Xml project team our one and the only lawyer - XML MVP Daniel Cazzulino aka kzu has signed a license for Microsoft to use and distribute the Mvp.Xml library. That effectively means Microsoft can (and actually wants to) use and distribute XInclude.NET and the rest Mvp.Xml goodies in their products. Wow, I'm glad XML MVPs could come up with something so valuable than Microsoft decided to license it. Mvp.Xml project is developed by Microsoft MVPs in XML technologies and XML Web Services worldwide. It is aimed at supplementing .NET framework functionality available through the System.Xml namespace and related namespaces such as System.Web.Services. Mvp.Xml library version 1.0 released at January 2005 includes Common, XInclude.NET and XPointer.NET modules. As a matter of interest - Mvp.Xml is an open-source project hosted at SourceForge.
Through the use of
Exchange email outsourcing or your own dedicated
Microsoft Exchange server you may find that a good
Microsoft Exchange server can help you out with your business communications
in ways only
Exchange 2007 hosting truly can.
Erik Meijer, one of designers of Haskell98 and C-omega languages will be presenting an interesting webcast at Tuesday, May 03, 2005 10:00 AM (GMT-08:00): MSDN Webcast: Language Design: Helping Programmers Program Better (Level 300)Register here. Almost 6 months after it's been announced that Microsoft won't ship XQuery implementation in the .NET 2.0, StylusStudio (maker of the namesake XML IDE) decided to run an online petition "XQuery for all" to urge Microsoft change the mind. Well, as a marketing action it's ok, but the petition itself is hopeless being ridiculously late. Asking Microsoft to include an implementation for a Working Draft technology, which they decided not to ship at least half a year ago and after Beta2 is out is a weird idea. Sorry guys, I won't sign it. Back in October 2004 - I would sign it for sure, but not now. I call it the blogsphere shadow effect - sometimes we bloggers get blind and see no other parts of the world. Dare Obasanjo announced (in his blog of course) that XQuery is cut from .NET 2.0 back in October 2004 and we all discussed that (in blogs of course) for months, until it became clear that there are some developers out there, who just don't read blogs and so still playing with condemned XQuery bits in early .NET 2.0 betas. Then XML team published an official announce in January. And now in May we've got this petition, cool but too late. Small advice for StylusStudio - one gotta read blogs in this century to be informed early. |
Recent Comments