Click here to Skip to main content
12,952,273 members (43,622 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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" ?>
    <TemplatesFolder>E:\Newsletter Templates (Email)\</TemplatesFolder>

Read by this code :

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

Gives this error:

There are multiple root elements. Line 3, position 2.

What am I doing wrong ?!?
Posted 15-Jan-13 4:25am
richcb 15-Jan-13 10:54am
Does the space after your encoding in the XML declaration have anything to do with that?
Sergey Alexandrovich Kryukov 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?
Marcus Kramer 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 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.
Gary Heath 15-Jan-13 13:44pm
Do you mean the first line ? creates that line so I guess it's OK !!!

1 solution

Rate this: bad
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).

Gary Heath 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 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 15-Jan-13 14:33pm
You are very welcome.
Good luck, call again.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
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