none
XML String occasionally returns empty causing a Root Element Missing error RRS feed

  • Question

  • I support a 12-year old web-site application.  Part of the application builds an XML document via a Java Script method that collects various questions and their possible answers for display, which can vary due to specific client-related criteria on each question. The user can see the listed questions and possible answers for each client and provide the necessary answers.  The update process used has the following code:
    Protected Sub btnUpdateRecord_Click(sender As Object, e As EventArgs) Handles btnUpdateRecord.Click
    
    		Dim objDOMDocument As New System.Xml.XmlDocument 'global to hold the passed xml docment from the client
    
    		objDOMDocument.LoadXml(HiddenXMLIsland.Value.ToString())
    		''If HiddenXMLIsland.Value.ToString() > String.Empty Then
    		SaveSpecialNeeds(objDOMDocument)
    		''Else
    		''EM.InnerText = "Please ensure you have answered all special needs questions."
    		''End If
    
    	End Sub
    it all works fine most of the time but on occasion the highlighted LoadXml statement will throw a "Root Element Missing" error and have been able to trace it the HiddenXMLIsland.Value.ToString(), which is the string of questions with the answers provided, comes back as an empty string.  Closing and reopening the session the providing the same answers for the same client will work as designed.  I have been unable to determine why this seemingly random error occurs or what I can do to prevent it.  Can you please suggest how this can occur and how I can preclude its occurrence?

    Ron K.

    Thursday, October 5, 2017 2:24 PM

All replies

  • If HiddenXMLIsland.Value is empty then you should get the error.  Check before loading

            Dim objDOMDocument As New System.Xml.XmlDocument 'global to hold the passed xml docment from the client
            If Not String.Empty.Equals(HiddenXMLIsland.Value.ToString) Then
                objDOMDocument.LoadXml(HiddenXMLIsland.Value.ToString())
                SaveSpecialNeeds(objDOMDocument)
            End If
    


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it." - MSDN User JohnWein    Multics - An OS ahead of its time.

    Thursday, October 5, 2017 3:04 PM

  • Hi Ron_Kunce,

    >> I support a 12-year old web-site application.  Part of the application builds an XML document via a Java Script method that collects various questions and their possible answers for display, which can vary due to specific client-related criteria on each question. The user can see the listed questions and possible answers for each client and provide the necessary answers.  The update process used has the following code:

    thanks for posting here.

    For your case about ASP.NET, please go to the ASP.NET forum for getting suitable help.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 6, 2017 5:38 AM