Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


'EndElement' is an invalid XmlNodeType

Posted on 2010-01-05
Medium Priority
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, www.amazingfacts.org</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
  • 5
  • 5
LVL 96

Expert Comment

by:Bob Learned
ID: 26184425
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

ID: 26184757
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
ID: 26184799
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?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 26184934
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
ID: 26185018
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

ID: 26185066
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

Bob Learned earned 1500 total points
ID: 26186574
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

ID: 26186950
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
ID: 26418338

Author Closing Comment

ID: 31673133
Went to a different forum for help on this one ...

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

578 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