views:

378

answers:

1

I'm working with some SQL Report definition files (RDLs), using LINQ to extract component query statements for validation. I'm trying to extract the <DataSet> elements from under the <DataSets> element. I seem to be getting hung up with one of the elements under <DataSet><Fields><Field> which has a namespace qualifier <rd:TypeName>

I've been using LINQ to XML for other parts of the files where there is no namespace qualifiers with no trouble, by specifying a default namespace. The RDL specifies two namespaces:

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"&gt;


When I try to get the <DataSets> element, however, I get the following error:

System.Xml.XmlException - The ':' character, hexadecimal value 0x3A, cannot be included in a name.

I know it has to do with the namespace qualifier (rd:) in one of the child elements, but I'm having difficulty getting a LINQ expression that works. Any help would be appreciated. Thanks!

+1  A: 

Are you using C# or VB.NET? In VB you can import xml namespaces with Imports statements the same way you reference other .NET namespaces.

If you're using C#, then LINQ to XML is the one place you should consider adding a VB project to your C# solution.

Either way, Beth Massi has a great How Do I Video Series covering LINQ to XML in VB.NET #8 talks about Importing XML namespaces.

Dennis Palmer
Thanks for the answer Dennis. I've seen some of the syntactic sugar VB has for LINQ/XML stuff and it looks good. I'm using C# in the main. I was able to work through it. I had suspected that it had to do with the namespaces and it turned out that I was not correctly qualifying them. It took a bit of trial and error though to get it to go. Thanks again!
BobC