'EndElement' is an invalid XmlNodeType

Posted on 2010-01-05
Last Modified: 2012-05-08
What does this error mean?  Below is the XML file and the code that parses through it.  Not sure what the issue is ... does anything look out of place?  The actual error is:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: 'EndElement' is an invalid XmlNodeType. Line 38, position 7.

The XML File
 <Title>The Last Little Big Horn</Title>
 <Author>Pastor Doug Batchelor</Author>
 <Copyright>Amazing Facts 2009,</Copyright>
 <Description>Amazing Facts Presents</Description>
Dim strXMLFile As String = Me.XMLSource

Dim objXMLTR As New XmlTextReader(strXMLFile)

Dim ProgramAttribute As String = Nothing

Dim FileName As String = Nothing

Dim blnGotMetaData As Boolean = False

Dim bNested As Boolean

Dim PlaylistID As Integer = 0

lblTitle.Text = ""

lblAuthor.Text = ""

lblDuration.Text = ""

lblCopyright.Text = ""

lblDescription.Text = ""

FileName = ""


Do While objXMLTR.Read

    If objXMLTR.NodeType = XmlNodeType.Element Then

        bNested = True

        ProgramAttribute = objXMLTR.Name

    ElseIf objXMLTR.NodeType = XmlNodeType.Text Or objXMLTR.NodeType = XmlNodeType.CDATA Then

        bNested = False

        Select Case UCase(ProgramAttribute)

            Case "TITLE"

lblTitle.Text = objXMLTR.Value & "<br>"

blnGotMetaData = True

If objXMLTR.Value.length < 12 Then

    blnGotMetaData = False

End If

            Case "AUTHOR"

lblAuthor.Text = objXMLTR.Value & "<br>"

            Case "DURATION"

lblDuration.Text = "Duration: " & objXMLTR.Value & "<br>"

            Case "ELAPSEDTIME"

lblElapsedTime.Text = "Elapsed Time: " & objXMLTR.Value & "<br>"

            Case "PLAYLISTID"

PlaylistID = CInt(objXMLTR.Value)

            Case "COPYRIGHT"

lblCopyright.Text = objXMLTR.Value & "<br>"

            Case "FILENAME"

FileName = Left(objXMLTR.Value, InStr(objXMLTR.Value, ".") - 1)

If (WeekdayName(Weekday(Today))) = "Friday" And (Hour(Now)) >= 18 Then

    pnlOffer.visible = False

ElseIf (WeekdayName(Weekday(Today))) = "Saturday" And (Hour(Now)) <= 19 Then

    pnlOffer.visible = False



End If

            Case "DESCRIPTION"

lblDescription.Text = objXMLTR.Value & "<br>"

        End Select

        ProgramAttribute = ""

    End If



Open in new window

Question by:afacts
    LVL 96

    Expert Comment

    by:Bob Learned
    I would suggest that the XmlDocument class, and valid XPath expressions would be easier to use to parse XML, than the XmlTextReader class.

    Author Comment

    everything I've read seems to indicate that xmltextreader is the most efficient method as far as performance.
    LVL 96

    Expert Comment

    by:Bob Learned
    If it is important to have efficient code, then the XmlTextReader is the correct choice.  But, the code that you create is more complex, and harder to debug, so if speed is not important, then the XmlDocument is easier to code against (and debug).

    When do you get that error?

    Author Comment

    We're using the DNN content management system ... this error occurs while trying to upgrade from version 4.9.1 to 5.1.4 ...
    LVL 96

    Expert Comment

    by:Bob Learned
    I don't have any experience with DNN, and it appears to be a bug in the software.  Is that the code that you showed above?

    Author Comment

    No ... the code shown above is from the custom module that the upgrade script stops at.  Apparently the problem lies in there somewhere.  
    LVL 96

    Accepted Solution

    That XML works with the code that you have shown, so the error doesn't make any sense.  Are you able to debug, and make sure that the XML is exactly like you have shown?

    Author Comment

    yeah I couldn't really make sense of it either.  I haven't debugged but I have verified that the XML is what is expected.  I've put up a post in the DNN forum as well and am hoping for some insight there.  Thanks for your help ...
    LVL 96

    Expert Comment

    by:Bob Learned

    Author Closing Comment

    Went to a different forum for help on this one ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now