2.0 Framwork Enhancements on System.XML - And misc ramblings

Published Fri, Aug 19 2005 21:53 | William

For the past few weeks, I've been upskilling as the lower cased one calls it.  I'm also to get back into the groove at the newsgroups and about the only thing I'm slacking on is support over at my beloved Devbuzz which I'll be getting back into this weekend.  Stuff I've been working on mainly consists of learning System.Xml inside and out (and of course XPath and XSLT), Speech Server and miscellaneous tidbits of 2.0 stuff. 

The fact that I'm an ADO.NET junkie is probably readily obvious.   And recently, I've realized that as much as I love ADO.NET, I've been using it as a crutch.  Don't get me wrong, this has nothing to do with flaws in ADO.NET, it has flaws to do with Bill.  So why is it  a crutch?  Well, the quote is attributed to a lot of different people, but it says essentially “He who is good with a hammer sees the world as a nail.”  This is particularly true in my case.  I don't think there's a problem out there that I can't solve using a DataRelation, DataTable.Select, DataTable.Compute, GetChildRows and WriteXml, ReadXml.  If it's XML and I need to manipulate it, I can read it into a dataset, count the tables, count the rows in each table and start DataTable.Select ing or DataView.RowFilter ing.  The problem arises when I need to get it back into XML.  And what I often do is just use WriteXml and work around it (or tell guy on the other end to work around it).  This is LAME on my part so I decided to cure it.

Well, that's my story and I'm sticking with it.  Probably the 'real' reason I decided to learn XML is because I wanted to outPimp el Maliko in ADO.NET and I can't get there without XML.  Actually, that's not the real reason either.  The real reason is because theres a newly minted MVP who's notorious for convoluted and inaccurate answers and I've been reading his posts.  I typically look down my nose at him with disdain b/c I think he's a jerk and his answers are either incorrect or plagairized.  Anyway, every friggin XML question that pops up, he uses the same method I did.  People ask about XPathIterators and he goes into 'load it into a dataset'.  I was never that bad but I was close.  Anyway, I'm 1/3 of my way to my goal.  Right now I own a few chunks of the System.Xml namespace, XPath in particular.  XSLT is giving me a little trouble, not so much with the syntax but wiht knowing what the f*** I want to transform everything to. 

If you are using DataSets and you need to give people Xml in a specific format, probably the best bet is to use Xslt.  From what I can tell, it's either that, or iterate the DataTables and build an XML document as you iterate them.  This is a royal pain in the a33 and of very little value. Code wise it's a nightmare and if you need to change the output, you need to recompile as opposed to just editing your Xslt.

 

String FailoverNamespace = "williamgryan.cuckoozbackup.com";

xmlPen.WriteStartDocument();
xmlPen.WriteStartElement("Cuckooz", PrimaryNamespace);
xmlPen.WriteStartElement("Cuckoo", PrimaryNamespace);
xmlPen.WriteEndElement();
xmlPen.WriteEndElement();
xmlPen.WriteEndDocument();
xmlPen.Close();
2.0 Way
Now you can just use the static Create method
XmlWriter xmlPen = XmlWriter.Create
(@"C:\Upskilling\XML\samplecuckoo.xml");
Ok, not much different, until you look at the friggin
overloads. Now you can use the
XmlWriterSettings class...
XmlWriterSettings docSettings = new XmlWriterSettings();
docSettings.Indent = {true/false};
docSettings.CloseOutput = {true/false};
docSettings.Encoding = 'Any value of the Encoding
enumeration ie UTF16
docSettings.ConformamceLevel =
ConformanceLevel.Fragment;
You can set most of the behavioral settings here and then
just pass it in the in
the constructor:
XmlWriter xmlPen = XmlWriter.Create
(@"C:\Upskilling\XML\samplecuckoo.xml", docSettings);

Ok, this is a lame example I know. I'm working on a class to read through the RSS feed using some of the new 2.0 Objects.  Let me finish that up and I'll post it in a few hours.

The long and short of it is though - that XML is becoming a lot more data centric, particularly in the 2.0 framework and the days of getting by withouth really being able to navigate and manipulate it are coming to an end.  At least they are for me.

Comments

# William said on August 19, 2005 10:34 PM:

DoubleI,

The example is only a little bit lame.

Anyways, System.Xml, SystemXml.XPath and System.Xml.Xsl all went through big ugly changes from v1.0 to v1.1. I did a few XML projects in 1.0 and had to migrate them to 1.1 and it was painful. The changes in 1.1 were necessary to make .NET "better" (and obsoleted a bunch of standard methods). I'm guessing that I was in the minority with doing a 1.0 to 1.1 migration using XML. Tie that in with BizTalk 2000 to 2002 Migration (at that time) and there were plenty of consulting dollars to be had.

I haven't had a chance to look at .NET 2.0's XML yet, but I've heard good things. I'm hoping that the .NET XML teams made the move easier.

You do realize that by getting a jump on 2.0 XML you are already outpimpin' me. We just can't have that now, can we?

---O

# William said on August 21, 2005 5:42 PM:

O - I doubt I got a jump on you - if so, it's just in one area. If you actually saw my progress on XML in 2.0, trust me, you probably tear an abdominal muscle laughing so hard. It looks like a bunch of stuff that does the same thing in most cases, although there's defintiely a lot of great stuff in it. The reason it all looks the same is b/c I'm a little slow sometime. Fortunately I can always run back to the System.Data.SqlClient namespace b/c it likes me for some reason and always works how I expect it to the first time I try ;-)

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications