Geeks With Blogs
NIEM Guy - NIEM, XML, and .NET Piecing it all together

Anyone using XML in .NET projects is probably aware of the several options available for working with XML within the .NET Framework (which I will tell you up front - I am a huge fan, nay, a cheerleader for .NET).  .NET provides a full set of classes to work with XML data and XML schemas.  With the release of Visual Studio 2008 and .NET 3.5 there are several new ways to work with XML using LINQ and many improvements to working with XML schemas (Intellisense support, etc).

The last few projects I did revolved around using the XML Serialization approach.  Basically I created an object model that was a 1:1 match of the object structure in the schema.  This evolved into a custom utility I created that generates VB classes based on the schema you feed it.  It will read nested schemas, understand inheritance, and it even can pick up on substitution groups (my favorite XML feature that I love and hate at the same time).

There are a few issues when doing this.  The first is that all string values in NIEM inherit from TextType.  So far I have not found a good way to express that with a class in .NET.  Essentially text type is a string with some additional attributes (that I have never seen used in an exchange).

Serialization and Deserialization can also be expensive with large documents.  Those are by far the easiest way to work with XML because you never actually have to deal with things like XSLT or XPATH, you are simply dealing with objects, collections, arrays, etc.  The .NET provided serialization attributes are extremely powerful and you can also do attribute overrides on the fly, ex If a class is marked <XmlElement(ElementName:="PersonName")> _ you can use an override to change it to serialize as "ViolatorsName" and pass that attribute just before you call the serializer.

This type of model also forces the very deep inheritance of the NIEM Model which is not a bad thing, unless you work with  people who are adverse to OO programming.  That just translates to more work for you.

At some point I would like to release an open source tool to support that code generation but currently it would only generate code for VB.NET which may not benefit everyone

In an upcoming post I will cover a new way to work with NIEM XML in .NET: Querying a  NIEM document with LINQ. 

Stay tuned...

Posted on Saturday, December 1, 2007 2:00 PM | Back to top

Comments on this post: Working with NIEM in .NET

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © niemguy | Powered by: