Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get a very strange (general) error message from the following code...
VB
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...
XML
<?xml version=1.0 encoding=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.
Posted
Updated 18-Dec-14 10:33am
v2
Comments
Maciej Los 18-Dec-14 16:41pm    
Proper spelling is: Maciej
;)
Maciej Los 18-Dec-14 16:43pm    
As far as i remember, you save data into xml file. Check this procedure.
Sean Donnahoe 18-Dec-14 21:29pm    
But the error being thrown is in the ModMain sub. It states...

[ModMain error: '1.0' is an unexpected token. The expected token is "" or '''. Line 1, Position 15.]

I really don't understand what the error is telling me, or where to look for the solution.

1 solution

Replace:
<?xml version=1.0 encoding=utf-8?>
with:
<?xml version="1.0" encoding="utf-8"?>
Do you see the difference?

See:
http://www.w3schools.com/xml/[^]
 
Share this answer
 
v3
Comments
Sean Donnahoe 18-Dec-14 21:30pm    
ok. got it.Thanks again Maciej. [spelled it correctly that time. :)]
Maciej Los 19-Dec-14 1:59am    
You're very welcome, Sean ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900