Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML VB.NET
Hopefully somebody can tell me what I’m doing wrong … I’ve never used an XML file before, so I’m obviously misunderstanding something ...

This XML file :

<?xml version="1.0" encoding="utf-8" ?>
  <Folders>
    <TemplatesFolder>E:\Newsletter Templates (Email)\</TemplatesFolder>
    <NewsLetterFolder>E:\Newsletters\</NewsLetterFolder>
  </Folders>

Read by this code :

    Do While (myXml.Read())
        If myXml.IsStartElement() Then
            If myXml.Name = "TemplatesFolder" Then
                myXml.Read()
                myTempFolder = myXml.Value
            End If
            If myXml.Name = "NewsLetterFolder" Then
                myXml.Read()
                myNlFolder = myXml.Value
            End If
        End If
    Loop

Gives this error:

There are multiple root elements. Line 3, position 2.
 
What am I doing wrong ?!?
Posted 15-Jan-13 5:25am
Comments
richcb at 15-Jan-13 10:54am
   
Does the space after your encoding in the XML declaration have anything to do with that?
Gary Heath at 15-Jan-13 13:44pm
   
Do you mean the first line ? VB.net creates that line so I guess it's OK !!!
Sergey Alexandrovich Kryukov at 15-Jan-13 10:55am
   
In what line? (Basically, the code fragment is very bad, ad-hoc stuff, a sure way to mess up...)
And it looks like you show one XML file and the exception (exception, not "error") is about another one. The one you show has only one root element. Or do you show only some fragments of it?
—SA
Marcus Kramer at 15-Jan-13 11:55am
   
Please stop asking people to come and look at your questions on other people's questions. Your question will appear in the list like everyone else's and will be dealt with as such. Persistent requests like this will irritate people and possibly cause them to flag you as a troll.
shaikh-adil at 15-Jan-13 12:51pm
   
sir it is bonding which me and sergey.. he helps me when i have some query. so i dont care what people thinks and flags me if they want. he likes helping me. and replies when i am in need.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please see my comment to the question. I am not sure that you show the same very file which causes the exception. Otherwise, how to explain your indentation in second line?
 
The code style you are using should not be used anyway, but I understand that you maybe just experimenting.
 
This exception, essentially, tells you that your input file is not a well-formed XML. The root XML element is always only one. You can remove you prolog (first line).
 
—SA
  Permalink  
Comments
Gary Heath at 15-Jan-13 13:49pm
   
Sergey, I see what *may* be the problem, I will experiment ... I created an XML file from within VS2010 as part of my Project & I then had to copy that file to my Debug folder. Thanks to you saying that I realised that I may have a problem and it seems that if I change the data in VS2010 in my XML file, this is NOT the same data as in the debug folder ... I have to change that independently or it goes out of step, and I have NOT done that !!!
 
It seems a bit odd to me that VS2010 would work like that, but it is what it is I suppose !!!
 
I will let you know if the changes make a difference ...
Gary Heath at 15-Jan-13 14:16pm
   
Yes, this was exactly the problem !!! I was updating the XML data tab within VS2010, but that isn't the file that gets read in debug mode !!!
 
A bit stupid if you ask me, but thanks for spotting it ... much appreciated.
Sergey Alexandrovich Kryukov at 15-Jan-13 14:33pm
   
You are very welcome.
Good luck, call again.
—SA

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

  Print Answers RSS
0 OriginalGriff 400
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 245
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100