<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>NIEM Guy - NIEM, XML, and .NET</title>
        <link>http://geekswithblogs.net/niemguy/Default.aspx</link>
        <description>Piecing it all together</description>
        <language>en-US</language>
        <copyright>niemguy</copyright>
        <managingEditor>chris.deweese@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>NIEM Guy - NIEM, XML, and .NET</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/niemguy/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>New Blog, Real Name</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/12/13/new-blog-real-name.aspx</link>
            <description>&lt;p&gt;After much thought I decided to begin blogging under my &lt;a href="http://christopherDeweese.com" target="_blank"&gt;own domain&lt;/a&gt;.  I've had it for a while but am going to slowly move things over there.  Thanks to all the readers who have left comments and e-mails here.  I'll be picking up the NIEM and .NET posts over at my permanent home on the web.  &lt;a href="http://blog.christopherdeweese.com/" target="_blank"&gt;Stop by&lt;/a&gt; and &lt;a href="http://feeds.feedburner.com/christopherdeweese" target="_blank"&gt;subscribe to the feed&lt;/a&gt; if you're interested!&lt;/p&gt;  &lt;p&gt;As I transition, I'll link things here until everyone gets caught up.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127886"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127886" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/127886.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/12/13/new-blog-real-name.aspx</guid>
            <pubDate>Sun, 14 Dec 2008 05:19:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/127886.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/12/13/new-blog-real-name.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/127886.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Passing a Transaction from a WCF Operation to a LINQ Data Context</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/05/28/passing-a-transaction-from-a-wcf-operation-to-a-linq.aspx</link>
            <description>&lt;p&gt;I have a situation where I want to use a transaction to keep track of a particular message process in order to roll back various parts if there is a failure.  The service operation is listening on a queue using the NetMSMQBinding and the operation is marked with the transaction properties of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationbehaviorattribute.aspx"&gt;OperationBehavior&lt;/a&gt; like so:    &lt;br /&gt;&amp;lt;OperationBehavior(TransactionAutoComplete:=True,TransactionScopeRequired:=True)&amp;gt; Public Sub SendHello( ...&lt;/p&gt;  &lt;p&gt;Using the above attribute enables the operation for transaction support.  The next trick is to grab the ambient transaction.  Doing this requires pulling in the System.Transactions namespace.&lt;/p&gt;  &lt;p&gt;Dim ambientTransaction as System.Transactions.Transaction = System.Transactions.Transaction.Current&lt;/p&gt;  &lt;p&gt;Once you have the ambient transaction you can pass that to your LINQ data context using the data context's Connection.EnlistTransaction method.&lt;/p&gt;  &lt;p&gt;myDataContext.Connection.EnlistTransaction(ambientTransaction)&lt;/p&gt;  &lt;p&gt;Note: Enlisting the transaction will require you to open and close your connection.  The code block worked for me.  I tested by throwing an exception after this block and my database insert (usp_InsertHello is a stored procedure) did not commit.   &lt;br /&gt;    &lt;br /&gt;Using myDataContext as new HelloWorldDataContext&lt;/p&gt;  &lt;p&gt;  myDataContext.Connection.EnlistTransaction(ambientTransaction)   &lt;br /&gt;  myDataContext.Connection.Open    &lt;br /&gt;  myDataContext.usp_InsertHello(helloText)    &lt;br /&gt;  myDataContext.Connection.Close&lt;/p&gt;  &lt;p&gt;End Using&lt;/p&gt;  &lt;p&gt;Many objects have an enlist transaction method that you can pass your transaction to.  The obvious benefit is that now all of the calls required for processing of the message will be handled in the scope of this transaction and if the method runs to completion all changes are committed - data operations are saved and the message is removed from the queue.  In the event of a failure the whole operation is rolled back and the message is returned to the queue.  &lt;/p&gt;  &lt;p&gt;For a poison message strategy just putting back at the top of the queue is not ideal; this is just an example of how transactions can be used across multiple calls in the context of an operation.&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8c0656d3-4fdc-4210-b033-e42fe56901b6" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/MSMQ" rel="tag"&gt;MSMQ&lt;/a&gt;,&lt;a href="http://technorati.com/tags/WCF" rel="tag"&gt;WCF&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Transactions" rel="tag"&gt;Transactions&lt;/a&gt;,&lt;a href="http://technorati.com/tags/LINQ" rel="tag"&gt;LINQ&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122466"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122466" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/122466.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/05/28/passing-a-transaction-from-a-wcf-operation-to-a-linq.aspx</guid>
            <pubDate>Thu, 29 May 2008 02:23:16 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/122466.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/05/28/passing-a-transaction-from-a-wcf-operation-to-a-linq.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/122466.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Contract First Design: A Study of OneDOJ</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/05/20/contract-first-design-a-study-of-onedoj.aspx</link>
            <description>&lt;p&gt;&lt;em&gt;Disclaimer:&lt;/em&gt; &lt;em&gt;This post speaks from an outsiders perspective.  My interactions with this initiative have been from a regional implementers standpoint and I am not privy to any of the decisions that led to the OneDOJ initiative.  This perspective comes from actual project work and reviewing open source information regarding the broader initiative.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;One of my first web service projects involved implementing a service from a WSDL provided to us by the federal partner in charge of a regional data sharing project.  This was my first brush with contract first and it did not occur to me until much later what this really meant.&lt;/p&gt;
&lt;p&gt;As part of the Department of Justice &lt;a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;taxonomyName=business_intelligence&amp;amp;articleId=278284&amp;amp;taxonomyId=9&amp;amp;intsrc=kc_top"&gt;OneDOJ&lt;/a&gt; initiative a new focus on information sharing created solutions which leveraged contract first / SOA approaches and principles.  Now the articles tout this as "one database" but in reality what is happening behind the scenes is a lot of federated searching among different data sources throughout the country.  The idea was that many regions or large cities have central databases already so instead of a lot of data duplication the DOJ could leverage this by creating a standard means for communicating justice data between involved partners.  The FBI has been at this for a while with things like NCIC but that data is limited as to what it communicates.  Extended data such as investigative records is not shared openly or easily.&lt;/p&gt;
&lt;p&gt;The answer to this is a standard called LEXS (Law Enforcement Exchange System) which is a subset of NIEM that defines structures and messages for exchanging different types of justice information between justice entities (Law Enforcement, Courts, etc).  LEXS also includes WSDL's for two major feature areas: Publish Discover (PD) and Search Retrieve (SR).  &lt;/p&gt;
&lt;p&gt;PD contains operations and messages to share the capabilities of your implementation.  Things like the version of LEXS you support, operations you support, etc.  When I implemented the WSDL for our exchange I did not implement PD so I cannot speak to much of it other than what I reviewed of the WSDL itself and the documentation.  I see the idea very much inline with the meta-data discovery that is mentioned in a lot of SOA discussions.  It is implemented (from what I can see) using a standard web service.  PD does not appear to implement any of the WS-Discovery protocols.  Not that it is a bad thing, I'm sure interop was a prime concern for this.&lt;/p&gt;
&lt;p&gt;SR contains operations and messages to share data.  This is the real meat of LEXS.  LEXS defines basic operations to request data using free text or structured searches and messages to return data formatted using the LEXS subset of NIEM.  There is also some extensibility built in so that entities can utilize existing subsets of NIEM within those return structures.  When I implemented SR for the project we are involved in I implemented version 2.0.  Currently LEXS is up to version 3.1.1. &lt;/p&gt;
&lt;p&gt;3.1.1 includes some major changes from 2.0 including the use of NIEM 2.0.  The WSDL's have changed slightly due to this so that they can accommodate for things you can do with NIEM 2.0 that were not possible in NIEM 1.0 or Justice XML.&lt;/p&gt;
&lt;p&gt;In the public sector very few companies would be concerned with actually implementing this specific schema.  I bring it up because I think the approach is very cutting edge; particularly because it is being driven by some of the largest and oldest institutions of our government that historically have problems sharing.  The DOJ has adopted an SOA approach to their information sharing and are following through on all fronts including governance.  I have spoke on a few conference calls with some of the decision makers and influencers behind this program.  I was very impressed that they spoke in terms of the WSDL contracts (using operation names) and were linking the business process to the actual capabilities expressed in LEXS.  They are addressing concerns from different partners on what and how much information to share, etc.  All in all a fascinating initiative to get a glimpse of.  &lt;/p&gt;
&lt;p&gt;Information sharing will not be the same going forward.  The dinosaur models of closed, custom formats are going bye-bye and being replaced with open formats and open standards. &lt;/p&gt;
&lt;p&gt;You can study more on LEXS by reviewing the schemas and documentation from the &lt;a href="http://www.it.ojp.gov/jsr/common/viewDetail.jsp?sub_id=256&amp;amp;view=yes&amp;amp;heading=9"&gt;Office of Justice Programs web site&lt;/a&gt;.&lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:02836cf3-67e8-4aa8-ad49-5f00a7a931c5" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/NIEM"&gt;NIEM&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/SOA"&gt;SOA&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/OneDOJ"&gt;OneDOJ&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://technorati.com/claim/dwmeint3mq" rel="me"&gt;  &lt;/a&gt;
&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122282"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122282" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/122282.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/05/20/contract-first-design-a-study-of-onedoj.aspx</guid>
            <pubDate>Wed, 21 May 2008 03:37:38 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/122282.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/05/20/contract-first-design-a-study-of-onedoj.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/122282.aspx</wfw:commentRss>
        </item>
        <item>
            <title>A Contract First Approach with WCF</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/05/20/a-contract-first-approach-with-wcf.aspx</link>
            <description>&lt;p&gt;One of the goals of a large state-wide multi-agency data sharing project my organization is participating in was to start with a partner designed WSDL and then implement it in the underlying technology of the partner's choice.  For my organization this technology is Windows Communication Foundation.  From it's inception the WSDL had to be simple and interoperable.  This is the second time I had started with a WSDL and then created a conformant service.&lt;/p&gt;  &lt;p&gt;My organization was one of the few that actually had a good base of experience with web services and NIEM.  We were best-suited to provide input into the WSDL and work with the leading partner (the grant receiver and "pockets").  This was a great exercise in a few things:&lt;/p&gt;  &lt;p&gt;Virtual project management: Several hundred miles separate all the partners.  My counter part at the lead partner is a young guy like me and preferred email over telephone (most times).  We hashed out the WSDL and several other items with a few brief to medium sized e-mails.&lt;/p&gt;  &lt;p&gt;Interoperability: The lead partner speaks Java, we speak .NET.  Other partners speak neither.  We learned to meet in the middle and actually came to appreciate the underlying technologies more (for the record I have never been a huge fan of Java - it's mostly the runtimes fault I think, not the language itself).&lt;/p&gt;  &lt;p&gt;Architectural leadership: This collaborative, open standards approach required a new outlook on connected systems and leadership in pushing change and promoting it to the other partners who have not caught up with recent developments like SOA, web services, and open standards.&lt;/p&gt;  &lt;p&gt;After two cuts we had a WSDL that encompassed the 7 operations we would need and defined the input and output messages.  Besides a few naming items (I was new to creating a WSDL from scratch) we ended up with a contract that is clear on the intent of each operation and what inputs/outputs it will have.  The outputs were generally simple, requiring only an acknowledgement of message receipt.  One of the design goals is to minimize the amount of time web service calls have to wait because much of the processing required will happen after the messages are received.&lt;/p&gt;  &lt;p&gt;To implement the WSDL I researched WCF and found that &lt;a href="http://msdn.microsoft.com/en-us/library/aa347733.aspx"&gt;Svcutil&lt;/a&gt; would do exactly what I needed.  I tinkered with the options and successfully got the WSDL to import in a very short amount of time.  The implementation language is VB.NET and everything came right in.  I did not like that the importer created a single file with all the requisite classes (data contract, message contract, service contract, and service stub).  I had started modeling a few of these early on and so I ended up cutting and pasting a few things but other than that it was very smooth.  I saw very few warning messages and overall was happy with the speed and results of using Svcutil.&lt;/p&gt;  &lt;p&gt;I sent the sample soap output (captured using &lt;a href="http://msdn.microsoft.com/en-us/library/ms733025.aspx"&gt;WCF tracing&lt;/a&gt;) and received positive feedback from the lead partner.  The message conformed to our contract and we will be able to proceed with a test soon.&lt;/p&gt;  &lt;p&gt;Now, I wish I could say that another partner involved had the same luck.  This partner is particularly behind in the web service area so in lieu of seeking training and developing their own knowledge base they purchased a magic box product.  I will not name this vendor as they have at least admitted to their fault in this.  This particular product is not able to import a WSDL the way WCF and Java can.  This led to a very sticky situation and some finger pointing that was eventually resolved when the vendor did state the product could not support what we were doing.  An unfortunate turn of events as we had already put considerable time into drafting the WSDL and message schemes and had already opted out of the bus approach in favor of the distributed contract based approach.&lt;/p&gt;  &lt;p&gt;Due to the agility of the lead partner they were able to create a client to work with the disfigured WSDL generated by the third-party utility (which incidentally is Java based).&lt;/p&gt;  &lt;p&gt;I oft wondered when the magic boxes would replace coders entirely but it seems as though we are not quite there.  I cannot say I was disappointed at this "set back".  The cost of this magic box and its training was about 4 times the cost that will be billed to the grant to have me do the work manually using an open design and open standards that will allow us to change the underlying implementation with minimal impact (other than time involved).&lt;/p&gt;  &lt;p&gt;Everything has it's place and I'm sure one day I will have a need for such a device.  Until then I will continue leveraging automated tools where handy and doing some manual labor to ensure services and components conform to good designs and practices.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122280"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122280" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/122280.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/05/20/a-contract-first-approach-with-wcf.aspx</guid>
            <pubDate>Wed, 21 May 2008 03:13:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/122280.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/05/20/a-contract-first-approach-with-wcf.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/122280.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Finding a NIEM Element using XDocument.Descendants</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/03/09/finding-an-niem-element-using-xdocument.descendants.aspx</link>
            <description>&lt;p&gt;This is part one of a multi-part post where I will show some of the techniques we've been using to parse NIEM XML documents using LINQ.  &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Microsoft has definitely put a lot of time into thinking out the System.Xml.Linq features.  When working with NIEM XML the essential thing to remember is that the only thing that ever really changes is the name of the tag and sometimes the namespace.  This makes NIEM very easy to parse with LINQ because LINQ does not look at an XML document like the DOM - a hierarchical structure, but it can look at it as a flat document as well and this is the power we will leverage.&lt;/p&gt;
&lt;p&gt;The key to this are a couple function calls (need to be refactored and probably could be abstracted a little more) named GetElement and GetElements.  GetElement will return the first instance of the element found based on the namespace and element name.  GetElements is the same but it returns an IEnumerable of XElement.&lt;/p&gt;
&lt;p&gt;Public Shared Function FindElement(ByVal doc As XDocument, ByVal elementName As String, ByVal xNamespace As XNamespace) As XElement &lt;br /&gt;
    Return doc.Descendants(xNamespace + elementName)(0) &lt;br /&gt;
End Function &lt;/p&gt;
&lt;p&gt;Public Shared Function FindElements(ByVal doc As XDocument, ByVal elementName As String, ByVal xNamespace As XNamespace) As IEnumerable(Of XElement) &lt;br /&gt;
    Return doc.Descendants(xNamespace + elementName) &lt;br /&gt;
End Function&lt;/p&gt;
&lt;p&gt;I tucked those methods in a class called XmlParser.  Notice the use of the + and not the &amp;amp;.  In VB when you join strings the + will throw compiler errors.  However for joining a XNamespace with a string element name you must use the + sign.  I didn't see this exact case documented anywhere but I just took a guess after the &amp;amp; was giving me compiler errors.&lt;/p&gt;
&lt;p&gt;Here is a sample doc - declared inline using the Xml literals feature in VB. &lt;br /&gt;
Dim doc As XDocument = &amp;lt;?xml version="1.0"?&amp;gt; &lt;br /&gt;
                       &amp;lt;myDoc xmlns="&lt;a href="http://niemguy.com/mydoc/1.0"&gt;http://niemguy.com/mydoc/1.0"&lt;/a&gt; xmlns:mydoc="&lt;a href="http://niemguy.com/mydoc/1.0"&gt;http://niemguy.com/mydoc/1.0"&lt;/a&gt; xmlns:nc="&lt;a href="http://niem.gov/core/2.0"&gt;http://niem.gov/core/2.0"&lt;/a&gt;&amp;gt; &lt;br /&gt;
                           &amp;lt;people&amp;gt; &lt;br /&gt;
                               &amp;lt;nc:Person&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonName&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:PersonGivenName&amp;gt;Chris&amp;lt;/nc:PersonGivenName&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonName&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:Date&amp;gt;1978-08-12&amp;lt;/nc:Date&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                               &amp;lt;/nc:Person&amp;gt; &lt;br /&gt;
                               &amp;lt;nc:Person&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonName&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:PersonGivenName&amp;gt;Sheila&amp;lt;/nc:PersonGivenName&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonName&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:Date&amp;gt;1977-02-24&amp;lt;/nc:Date&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                               &amp;lt;/nc:Person&amp;gt; &lt;br /&gt;
                               &amp;lt;nc:Person&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonName&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:PersonGivenName&amp;gt;David&amp;lt;/nc:PersonGivenName&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonName&amp;gt; &lt;br /&gt;
                                   &amp;lt;nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                                       &amp;lt;nc:Date&amp;gt;1982-06-05&amp;lt;/nc:Date&amp;gt; &lt;br /&gt;
                                   &amp;lt;/nc:PersonBirthDate&amp;gt; &lt;br /&gt;
                               &amp;lt;/nc:Person&amp;gt; &lt;br /&gt;
                           &amp;lt;/people&amp;gt; &lt;br /&gt;
                       &amp;lt;/myDoc&amp;gt;&lt;/p&gt;
&lt;p&gt;And finally, here is how we can use the GetElement functions to find some elements.&lt;/p&gt;
&lt;p&gt;Dim nameEl As XElement = XmlParser.FindElement(doc, "PersonGivenName", GetXmlNamespace(nc)) &lt;br /&gt;
Console.WriteLine(nameEl.Value) &lt;/p&gt;
&lt;p&gt;Dim birthDays As IEnumerable(Of XElement) = XmlParser.FindElements(doc, "PersonBirthDate", GetXmlNamespace(nc)) &lt;/p&gt;
&lt;p&gt;For Each birthday In birthDays &lt;br /&gt;
    Console.WriteLine(birthday...&amp;lt;nc:Date&amp;gt;.Value) &lt;br /&gt;
Next&lt;/p&gt;
&lt;p&gt;A key thing to note here is the use of GetXmlNamespace.  The GetXmlNamespace function is a framework method that returns the XNamespace based on the prefix of a namespace you have imported at the project or file level.  For reference are the file level imports I used:&lt;/p&gt;
&lt;p&gt;Imports &amp;lt;xmlns:mydoc="&lt;a href="http://niemguy.com/mydoc/1.0"&gt;http://niemguy.com/mydoc/1.0"&lt;/a&gt;&amp;gt; &lt;br /&gt;
Imports &amp;lt;xmlns:nc="&lt;a href="http://niem.gov/core/2.0"&gt;http://niem.gov/core/2.0"&lt;/a&gt;&amp;gt;&lt;/p&gt;
&lt;p&gt;The nice thing about GetXmlNamespace is that you get intellisense on the namespaces you have in your project or file.  This makes it really handy.  The drawback is that you can only get them from there, or at least I have not found a way to get them listed from an external source or the document itself.  For most exchanges that would be ok if you're custom tailoring it a little - but if you're after a generic parser then this may not be the way to go.&lt;/p&gt;
&lt;p&gt;Next post will describe a abstract (mustInherit) bass class that we created as a base document parser and then we extend it for special documents.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120403"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120403" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/120403.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/03/09/finding-an-niem-element-using-xdocument.descendants.aspx</guid>
            <pubDate>Sun, 09 Mar 2008 19:56:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/120403.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/03/09/finding-an-niem-element-using-xdocument.descendants.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/120403.aspx</wfw:commentRss>
        </item>
        <item>
            <title>VS 2008: Importing XML Namespaces at the project level</title>
            <link>http://geekswithblogs.net/niemguy/archive/2008/01/31/vs-2008-importing-xml-namespaces-at-the-project-level.aspx</link>
            <description>&lt;p&gt;While working on a NIEM parser library I found that you can import XML namespaces at the project level.  Previously I posted about doing this at the top of your .VB class file:&lt;/p&gt;
&lt;font color="#0000ff"&gt;
&lt;p&gt;&lt;font size="2"&gt;Imports&lt;/font&gt; &lt;font color="#6464b9"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#b96464"&gt;xmlns:nc&lt;/font&gt;&lt;font color="#6464b9"&gt;=&lt;/font&gt;&lt;font color="#555555"&gt;"&lt;/font&gt;&lt;font color="#6464b9"&gt;http://niem.gov/niem/niem-core/2.0&lt;/font&gt;&lt;font color="#555555"&gt;"&lt;/font&gt;&lt;font color="#6464b9"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;&lt;font size="2"&gt;That allows you to use the prefix nc: in LINQ queries to work with NIEM documents.  Well today I discovered you can add those at the project level.  Right click your project and go to properties.  In the properties window go to references.  Near the bottom you can type / paste your name space in (leave out the imports statement of course) and then click add user reference.  Voila!  You can now use that in any class in your project.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;img alt="Import XML namespaces at the project level" src="http://geekswithblogs.net/images/geekswithblogs_net/niemguy/7378/o_import%20xml%20namespaces.jpg" /&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119122"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119122" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/119122.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2008/01/31/vs-2008-importing-xml-namespaces-at-the-project-level.aspx</guid>
            <pubDate>Thu, 31 Jan 2008 13:15:51 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/119122.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2008/01/31/vs-2008-importing-xml-namespaces-at-the-project-level.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/119122.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Article: How to use the NIEM Schema Subset Generator</title>
            <link>http://geekswithblogs.net/niemguy/archive/2007/12/18/article-how-to-use-the-niem-schema-subset-generator.aspx</link>
            <description>&lt;p&gt;I wrote a very simple article on using the NIEM Schema Subset Generator.  There is a lot more to IEPDs and the NIEM model than what I conveyed but this will be a good starting point.&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;a class="singleposttitle" id="viewpost_ascx_TitleUrl" title="Title of this entry." href="http://geekswithblogs.net/niemguy/articles/how-to-use-the-niem-schema-subset-generator-to-build-a.aspx"&gt;How-to: Use the NIEM Schema Subset Generator to Build a NIEM Subset Schema&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117803"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117803" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/117803.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2007/12/18/article-how-to-use-the-niem-schema-subset-generator.aspx</guid>
            <pubDate>Tue, 18 Dec 2007 17:13:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/117803.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2007/12/18/article-how-to-use-the-niem-schema-subset-generator.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/117803.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Web Services - Exposing the Schema Contract when Using NIEM Schemas?</title>
            <link>http://geekswithblogs.net/niemguy/archive/2007/12/10/web-services---exposing-the-schema-contract-when-using-niem.aspx</link>
            <description>&lt;p&gt;In the new paradigm of contract first designs for services a lot of it revolves around exposing a contract that defines the operations and messages for a service.  In terms of Web Services (or WCF exposed via a web service) this also means exposing the schemas via the WSDL so that consumers know the inputs and outputs for that service and its methods.&lt;/p&gt;
&lt;p&gt;This is my big question: When working with NIEM how many are exposing their subset schemas to their web services and how many are using a generic "Package as string" approach where the package details are agreed upon outside the context of your service? &lt;/p&gt;
&lt;p&gt;I have seen this done both ways and recently have chosen to follow one direction.  In my most recent service adventure I modeled my messages to contain some required input parameters (need to know who is making the request and for what agency) and in my return message I have the generic "Package as string" where the package is going to be this very large collection of documents formatted in NIEM.  &lt;/p&gt;
&lt;p&gt;Returning "Package as string" is very ambiguous and will make a few people cringe or sneer when (if) they read this.  But there is a reason for this and it's two fold:&lt;/p&gt;
&lt;p&gt;1) In terms of Interop there are several technologies out there that do not support mulitple imported schemas in a WSDL and they also do not support substitutions via the WSDL.  (Noting that currently interop is not a major concern for my service but that does not mean I shouldn't be prepared for it).&lt;/p&gt;
&lt;p&gt;2) Imposing that any consumers must deserialize or validate that structure upon receipt.  This one really gets into the realm of performance.  Deserialization is an expensive process and so is schema validation and imposing that on a client could cause performance issues.  &lt;/p&gt;
&lt;p&gt;The disconnect in the contract will be that consumers will have to validate (if they choose to) the message against the schema post receipt.  This obviously has the consequence that if somehow the service returns an invalid message package than the consumer has to make a subsequent request to get a valid package.  So, in effect, that also would be a performance hit.  Far less likely to happen (yes, I trust my service) but it could.&lt;/p&gt;
&lt;p&gt;In other exchanges not exposing the full NIEM / Justice XML schema subset via the service has been the norm.  The schemas are handled outside the context of the actual receiving of a message from ther service(s) involved.  &lt;/p&gt;
&lt;p&gt;During one project the weakness was thought to be in .NET; ironically it turns out .NET far better support for schemas in WSDL than others.  Which does illustrate Microsofts great adoption of XML and all it's related technologies.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9461ac62-c605-4e18-bbc0-b18131e2c976" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/NIEM"&gt;NIEM&lt;/a&gt; &lt;a rel="tag" href="http://technorati.com/tags/WCF"&gt;WCF&lt;/a&gt; &lt;a rel="tag" href="http://technorati.com/tags/Contract First"&gt;Contract First&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117541"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117541" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/117541.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2007/12/10/web-services---exposing-the-schema-contract-when-using-niem.aspx</guid>
            <pubDate>Mon, 10 Dec 2007 15:26:43 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/117541.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2007/12/10/web-services---exposing-the-schema-contract-when-using-niem.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/117541.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Piecing it all together</title>
            <link>http://geekswithblogs.net/niemguy/archive/2007/12/06/piecing-it-all-together.aspx</link>
            <description>&lt;p&gt;The subtitle of this blog started out as gluing it all together.  I quickly realized that when thinking in terms of a loosely coupled environment glue isn't necessarily the best tool in your tool box.  &lt;/p&gt;
&lt;p&gt;I will try to post a little more in depth follow up to &lt;a href="http://geekswithblogs.net/niemguy/archive/2007/12/05/querying-a-niem-xml-document-using-linq.aspx"&gt;Querying a NIEM XML Document With LINQ&lt;/a&gt; as soon as I can.  After some review I realized just how reusable some of the parsing methods I wrote are.  Wouldn't it be nice to have a single NIEM XML parser that you could extend if you received additional elements not in the base NIEM schemas?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117425"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117425" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/117425.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2007/12/06/piecing-it-all-together.aspx</guid>
            <pubDate>Thu, 06 Dec 2007 12:05:11 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/117425.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2007/12/06/piecing-it-all-together.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/117425.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Querying a NIEM XML Document Using LINQ</title>
            <link>http://geekswithblogs.net/niemguy/archive/2007/12/05/querying-a-niem-xml-document-using-linq.aspx</link>
            <description>&lt;p&gt;If you are not familiar with the new &lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx"&gt;LINQ&lt;/a&gt; syntax in .NET 3.5 I recommend you read up on that first. Language Integrated Query (LINQ) is the new foundation for querying anything (I mean anything) in .NET and a lot of effort has been put into LINQ and XML integration.  I did some research a few months back on it but it was only recently that I realized how much Microsoft put into LINQ to XML.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I am a huge fan of intellisense&lt;/strong&gt;.  That is the best thing that MS ever perfected in Studio.  I spend a lot of time making sure things show up properly via intellisense and it really irks me if something isn't there.  Studio 2008 (I've used Professional and now Team Development edition) has the best intellisense support of any version yet and MS pulled out all the stops and you can get intellisense darn near everywhere in a VB, XML, or other types of files.&lt;/p&gt;
&lt;p&gt;Before you go on I highly recommend spending the 15 minutes &lt;a href="http://msdn2.microsoft.com/en-us/vbasic/bb887654.aspx"&gt;watching this video&lt;/a&gt; from &lt;a href="http://blogs.msdn.com/bethmassi/"&gt;Beth Massi&lt;/a&gt; of the VB Team.  She covers how to add intellisense support for XML Schemas and documents inside of LINQ queries.&lt;/p&gt;
&lt;p&gt;Prerequisites: &lt;br /&gt;
1) A NIEM conformant XML schema loaded into your Visual Studio Solution.  Be sure to have it properly seated in its folders.  Here is a screenshot of mine:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/niemguy/gallery/image/4352.aspx"&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/niemguy/7378/r_01-SchemaSetup.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If you generated your schemas from the Schema Subset Generator on the NIEM tools page just copy the folder structure from the zip file into your project.  Studio should immediately start parsing it.&lt;/p&gt;
&lt;p&gt;2) Import your XML namespaces into the class file you are working in.  This is done via the new Import &amp;lt;xmlns&amp;gt; statement like so:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/niemguy/gallery/image/4353.aspx"&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/niemguy/7378/r_02-XmlnsImports.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;[The blacked out line is because I covered over one that I didn't want you to see :)]&lt;/p&gt;
&lt;p&gt;3) Load a valid XML Document.  If you have one on disk you can load it by creating an XDocument and calling the load method and passing the file path like so: &lt;br /&gt;
Dim Doc as XDocument = XDocument.Load("C:\myfile.xml")&lt;/p&gt;
&lt;p&gt;If you have a string of XML in a variable you can load it calling the parse method of the XDocument:&lt;/p&gt;
&lt;p&gt;Dim MyXml as string = "&amp;lt;root&amp;gt;&amp;lt;tag1&amp;gt;test&amp;lt;/tag2&amp;gt;&amp;lt;/root&amp;gt;"&lt;/p&gt;
&lt;p&gt;Dim Doc as XDocument = XDocument.Parse(MyXml)&lt;/p&gt;
&lt;p&gt;Once you have those things set up you are ready to begin.  As with any type of query language you must know the structure.  Studio will give you intellisense during the queries but you have to closely look for a check mark indicator to know that your selection is valid for where you are at in your structure.  Example:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/niemguy/gallery/image/4354.aspx"&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/niemguy/7378/r_03-Intellisense.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Note the small green circle with the check.  That indicates that my choice is valid for where I was in the path -nc:Person.nc:PersonName.nc:PersonGivenName.  I could have typed something else in there and it would have accepted it, however it would fail at runtime.&lt;/p&gt;
&lt;p&gt;In the query above I am selecting a Person element from the document based on the Reference Id.  From there I am drilling down to their name.  When calling that method I am passing the string Id I want to find.&lt;/p&gt;
&lt;p&gt;Example Document: &lt;br /&gt;
&amp;lt;j:CitationSubject&amp;gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;lt;nc:RoleOfPersonReference s:ref="P1"&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;lt;/j:CitationSubject&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;nc:Person s:id="P1"&amp;gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;lt;nc:PersonName&amp;gt;&amp;lt;nc:PersonGivenName&amp;gt;Chris&amp;lt;/..&amp;gt;&amp;lt;/..&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;lt;/..&amp;gt;&lt;/p&gt;
&lt;p&gt;The Query would return "Chris" as it is the value of the PersonGivenName element.  Because FirstNameQuery is an IEnumerable of XElement I use the index to return the first result because that is the one I want (and when matching by Id like I am there should only ever be one). [NB: Because I was demoing the intellisense I had to cut off the .Value at the end of the select.  The full select should look like: Select person...&amp;lt;nc:PersonName&amp;gt;...&amp;lt;nc:PersonGiveName&amp;gt;.Value]&lt;/p&gt;
&lt;p&gt;The only caveat is that LINQ's Intellisense does not support substitution groups.  In the normal XML document intellisense in Studio 2008 you will get a list of valid substitutions (nc:AddressRepresentation anyone?).  It is not a big deal, you just have to know what tag to put in.  For example, under nc:Location.nc:LocationAddress there is a substitution called "AddressRepresentation".  I substitute nc:LocationStreet at that point.  With LINQ, I have to manually type that in, but after I get to the nc:LocationStreet the intellisense picks back up and I get choices like nc:StreetName, etc.  I know, they can't spoil us but if they added that I would fly to Seattle to buy someone coffee!&lt;/p&gt;
&lt;p&gt;So how does this fare versus serialization?  I ran some very rudimentary benchmarks.  For loading a document with 50 of my citations in it (for reference I inherited from j:CitationType and extended it...a bunch) it took LINQ 00:00:00.0624724 ms to load the document.&lt;/p&gt;
&lt;p&gt;LINQ: &lt;br /&gt;
Start: 21:17:59.2930220 &lt;br /&gt;
Document Loaded: 21:17:59.3554944 &lt;br /&gt;
&lt;strong&gt;Load Time 00:00:00.0624724&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The same document after invoking a serializer to deserialize the XML to the matching class structure: &lt;/p&gt;
&lt;p&gt;Deserializer &lt;br /&gt;
Start: 21:20:38.8631497 &lt;br /&gt;
Serialize Complete: 21:20:39.5815823 &lt;br /&gt;
&lt;strong&gt;Load Time 00:00:00.7184326&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That is quite a substantial difference to me considering the parser I'm developing may need to chew through thousands of citations at a time.&lt;/p&gt;
&lt;p&gt;I see a lot of potential for using LINQ to query NIEM conformant XML.  On the XML generation side I will still use the serializer for the time being.  But when it comes to parsing, I'm going to push using LINQ because of its speed and flexibility.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9461ac62-c605-4e18-bbc0-b18131e2c976" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/NIEM"&gt;NIEM&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/XML"&gt;XML&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/LINQ"&gt;LINQ&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/.NET%20XML"&gt;.NET XML&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/VB.NET"&gt;VB.NET&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/LINQ%20to%20XML"&gt;LINQ to XML&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117414"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=117414" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/niemguy/aggbug/117414.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>niemguy</dc:creator>
            <guid>http://geekswithblogs.net/niemguy/archive/2007/12/05/querying-a-niem-xml-document-using-linq.aspx</guid>
            <pubDate>Thu, 06 Dec 2007 03:44:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/niemguy/comments/117414.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/niemguy/archive/2007/12/05/querying-a-niem-xml-document-using-linq.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/niemguy/comments/commentRss/117414.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>