Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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
<?xml version="1.0" encoding="utf-8" ?>
  <Folders>
    <TemplatesFolder>E:\Newsletter Templates (Email)\</TemplatesFolder>
    <NewsLetterFolder>E:\Newsletters\</NewsLetterFolder>
  </Folders>


Read by this code :

VB
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
Comments
Richard C Bishop 15-Jan-13 10:54am    
Does the space after your encoding in the XML declaration have anything to do with that?
Gary Heath 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 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
fjdiewornncalwe 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.

1 solution

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
 
Share this answer
 
Comments
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.
—SA

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