I get a very strange (general) error message from the following code...
Public Customers As List(Of Customer) = Nothing
Public sFileName As String = "C:\Users\sean\Documents\CustDB.xml"
Sub LoadXmlData(sFileName As String)
Dim xDoc As XDocument = Nothing
Dim custList As IEnumerable = Nothing
Try
Customers = New List(Of Customer)
xDoc = XDocument.Load(sFileName, LoadOptions.PreserveWhitespace)
custList = From customer In xDoc.Elements("CustDB").Elements("Customer") _
Order By customer.Value Ascending _
Select Nm = customer.Elements("Name").Value,
Ad1 = customer.Elements("Street").Value,
Ad2 = customer.Elements("CityStateZip").Value,
Ph = customer.Elements("Phone").Value,
Fx = customer.Elements("Fax").Value,
Ce = customer.Elements("Cell").Value,
Oth = customer.Elements("Other").Value,
Atn = customer.Elements("Attn").Value,
Eml = customer.Elements("Email").Value,
SaPe = customer.Elements("SalesPerson").Value,
AcTy = customer.Elements("AcctType").Value
For Each cl In custList
Dim cu As Customer = New Customer
With cu
.CustName = cl.Nm
.Street = cl.Ad1
.CityStateZip = cl.Ad2
.Phone = cl.Ph
.Fax = cl.Fx
.Cell = cl.Ce
.Other = cl.Oth
.Attn = cl.Atn
.Email = cl.Eml
.SalesPerson = cl.SaPe
.AcctType = cl.AcTy
End With
Customers.Add(cu)
Next
Catch ex As Exception
MsgBox("ModMain error: " & ex.Message, MsgBoxStyle.Exclamation, "Error...")
Finally
xDoc = Nothing
End Try
End Sub
The XML is structured like this...
=1.0=utf-8?
<CustDB>
<Customer>
<Name>A&T Window Cleaning</Name>
<Street></Street>
<CityStateZip></CityStateZip>
<Phone></Phone>
<Fax></Fax>
<Cell></Cell>
<Other></Other>
<Attn>Troy</Attn>
<Email></Email>
<SalesPerson></SalesPerson>
<AcctType></AcctType>
</Customer>
<Customer>
<Name>Adventure Chrisitan Church</Name>
<Street></Street>
<CityStateZip></CityStateZip>
<Phone></Phone>
<Fax></Fax>
<Cell></Cell>
<Other></Other>
<Attn>Richard Mosqueda</Attn>
<Email></Email>
<SalesPerson></SalesPerson>
<AcctType></AcctType>
</Customer>
...
</CustDB>
The screen shot of the error can be found
here.
The only thing I changed from when Meicji (I think I spelled that right) helped me with this is the addition of the 'AcctType' in the XML and parsing.