Advertisement

06.17.2008 at 05:43AM PDT, ID: 23491224
[x]
Attachment Details

Linq to XML issues

Asked by alan_ITG in Language Integrated Query - LINQ

Tags: Linq to XML VB.Net, Internet Explorer 6.0

Hi,

I am trying to import an MS Excel XML document (2003 version of XL).

The code being used is as shown.

The issues I have are as follows:-

1) The For Each R in Sheet....<Row> section works fine and iterates through the rows in the document.
However, when the code reaches the Linq query (even when the loop is commented out) the Linq   query returns a NULLReference Error.

Any ideas why?

2) Often when setting up Linq queries the variable in the for each loop (x in this case) used to iterate through the Linq query results generates an error in VB. The error states that the variable has not been defined.  

I believe that these variables do not have to be defined as they are anonymous types.  Can someone advise why this error happens?

regards,


Alan

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
Imports System.Reflection
Imports System.IO
Imports <xmlns="urn:schemas-microsoft-com:office:spreadsheet">
Imports <xmlns:o="urn:schemas-microsoft-com:office:office">
Imports <xmlns:x="urn:schemas-microsoft-com:office:excel">
Imports <xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
Imports <xmlns:html="http://www.w3.org/TR/REC-html40">
 
Public Class DoXml
 
 
Sub ProcessXMLFile
 
 
        Try
 
            Dim sheet As XDocument = XDocument.Load(fname)
	    'This works
            For Each R In sheet...<Row>
                Debug.Print(R.<Cell>(0).Value)
                Debug.Print(R.<Cell>(1).Value)
                Debug.Print(R.<Cell>(2).Value)
            Next
 
 
	    'This returns nullexception error
            Dim y = From d In sheet...<Row> _
            Let Source = d.<cell>(0) _
            Let SubSys = d.<Cell>(1) _
            Select _
             Source = Source.Value, _
             SubSys = SubSys.Value _
            Skip (1)
 
            For Each x In y
                iRowcount = iRowcount + 1
                Console.WriteLine("processing row: " & iRowcount & " : " & x.ToString)
            Next
 
        Catch ex As NullReferenceException
            'do nothing except report back
            console.writeline(vbTab & "No Records to load in " & FuncName)
 
        Catch ex As Exception
 
            Console.writeline(vbTab & "Error in LoadDespatchesXML: " & ex.Message)
 
        End Try
 
End Sub
 
End Class
[+][-]06.17.2008 at 09:03PM PDT, ID: 21809934

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.17.2008 at 11:55PM PDT, ID: 21810635

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 12:11AM PDT, ID: 21810685

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 01:01AM PDT, ID: 21810905

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.18.2008 at 01:03AM PDT, ID: 21810912

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 12:22AM PDT, ID: 21819930

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Language Integrated Query - LINQ
Tags: Linq to XML VB.Net, Internet Explorer 6.0
Sign Up Now!
Solution Provided By: alan_ITG
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628