简体   繁体   中英

What could be causing an XML Parsing Error: no element found?

I recently migrated an ASP site from my dev machine to a live server. All the pages except my FAQ page works just fine, but my FAQ brings up:

XML Parsing Error: no element found
Location: http://geniusupdate.com/GSHelp/faq.aspx
Line Number 1, Column 1:

The only changes I have made were changing the connection string on my SQL page from local to the string specified by my hosting service. Any tips on what I can do to find the root of this issue?

here is the source to my FAQ page:

<%@ Page Language="VB" MasterPageFile="~/theMaster.master" AutoEventWireup="false" CodeFile="faq.aspx.vb" Inherits="faq" Title="Untitled Page" %>
<%@ Import Namespace="sqlstuff" %>
<%@ Import Namespace="functions" %>

<asp:Content ContentPlaceHolderID="page_title" ID="theTitle" runat="server">
    FAQ</asp:Content>
<asp:Content ContentPlaceHolderID="column1_title" ID="col1Title" runat="server">
    <%=faqPageTitle(Request.QueryString("cid"))%></asp:Content>
<asp:Content ContentPlaceHolderID="column1" ID="columnContent" runat="server">

     <p>Click on a question to expand it to see the answer!</p>
     <p><%  If cID >= 0 Then
                Dim theFaq As New List(Of faqContent), iterate As Integer = 0
                theFaq = sqlStuff.getFaqs(cID)
                For Each oFaq As faqContent In theFaq
                    Response.Output.WriteLine("<h4 id={0} class={1}>Q: {2}</h4>", _
                                                 addQuotes("gsSwitch{0}-title", iterate), _
                                                 addQuotes("handCursor"), _
                                                 oFaq.Content.Question)
                    Response.Output.WriteLine("<div id={0} class={1}><string>A: </strong>{2}</div>", _
                                                 addQuotes("gsSwitch{0}", iterate), _
                                                 addQuotes("gsSwitch"), _
                                                 oFaq.Content.Answer)

                    iterate += 1
                Next
            Else
                Response.Output.Write("Here you can find a lot of information about eTHOMAS and how to expedite your office tasks.{0}", ControlChars.NewLine)
            End If
    %></p>
    <script type="text/javascript">
        var gsContent = new switchcontent("gsSwitch", "div")
        var eID = '<%= expandID %>'
        gsContent.collapsePrevious(true) // TRUE: only 1; FALSE: any number
        gsContent.setPersist(false)
        if(eID >= 0){
            gsContent.defaultExpanded(eID) // opens the searched FAQ
            document.getElementById('gsSwitch' + eID + '-title').scrollIntoView(true) // scrolls to selected FAQ
        }        
        gsContent.init()
    </script>
</asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_right_title" ID="rSideColTitle" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_right" ID="rSideColContent" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_left_title" ID="lSideColTitle" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="subcolumn_left" ID="lSideColContent" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="sidecolumn_title" ID="sideColtitle" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="sidecolumn" ID="sideCol" runat="server">
    <%  If cID >= 0 Then
            Response.Write(constructFaqSideMenu(CInt(Request.QueryString("cid"))))
        Else
            Response.Write(constructFaqSideMenu())
        End If
    %>
</asp:Content>

I found this on another forum link :

Well, it appears it's a bit of both. The message is generated by Firefox, but caused by the framework. For some reason, .NET generates a response type of "application/xml" when it creates an empty page. Firefox parses the file as XML and finding no root element, spits out the error message.

IE does not render the page, period. This is where the XML is coming from.

Here is the constructFaqSideMenu() function:

Public Shared Function constructFaqSideMenu(ByVal oSelID As Integer) As String
    Dim oCatList As New List(Of faqCategory)
    Dim oRet As New StringBuilder
    Dim iterate As Integer = 1, extraTag As String = ""

    oCatList = sqlStuff.getFaqCats

    oRet.AppendFormattedLine("<ul id={0}>", addQuotes("submenu"))
    oRet.AppendFormattedLine("    <li id={0}>FAQ Categories</li>", addQuotes("title"))
    For Each category As faqCategory In oCatList
        If iterate = oSelID Then
            extraTag = String.Format(" id={0}", addQuotes("active"))
        Else
            extraTag = ""
        End If
        oRet.AppendFormattedLine("    <li{0}><a href={1}>{2}</a></li>", extraTag, addQuotes("faq.aspx?cid={0}", iterate), StrConv(category.Title,         VbStrConv.ProperCase))
        iterate += 1
    Next
    oRet.AppendLine("</ul>")

    Return oRet.ToString
End Function

And here is the source of the blank page IE returns:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

This is a very old thread, but I found this while googling for the same problem and wanted to contribute a definitive answer for anyone else who searches for this in the future.

I got this error when an exception was thrown while the page directives were being parsed. I updated aspx files from source control, and the developer who checked them in had a different version of a 3rd party library of controls. The Register Assembly page directives referenced a version I didn't have, so the exception was thrown at this point. I'm assuming that this error shows up in the client when an exception is thrown so early in the page request life cycle that nothing at all is sent to the client.

We are logging all exceptions at the app level in Global.Application_Error , so I was able to get this info from the logs. We grab the last exception with the following code:

Server.GetLastError().GetBaseException()

I don't know anything about ASP.NET, but from my generic experience with web frameworks, it sounds like your application failed to produce any output at all. Usually that means that there was an exception before any output rendering took place, so try looking through the logs to find out what caused it...

I ran in to this and found at least for me it was because in C# WebAPI 2 if you return an empty Ok() result that it returns XML as content type. Even if you override it in the WebAPI config to not return XML ever. So my solution was to make this function in a Base Controller class I have and use it anywhere I need to return an empty OK() JSON response. One could make it more advanced for their needs but this is what I did. I guess you could maybe use an AttributeFilter as well maybe but I did this solution as it is same amount of code in Action.

protected IHttpActionResult OKJSONResult()
{
    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "", new MediaTypeHeaderValue("application/json"));
    return ResponseMessage(response);
}

当我部署到IIS时,我的所有页面都出现此问题,解决方案结果表明,运行应用程序池的帐户没有足够的权限来连接和执行数据库查询

If you are calling a .vb or .cs script from a .aspx page and get this error, add the following code to the .aspx page. FireFox needs to some semblance of valid mark up apparently. This worked for me.

<html>
<body></body>
</html>

I found this issue because URL was redirecting to a different location. Correcting that resolved the issue.

It was redirecting to http://localhost/forms/abc.aspx , however it should have been redirected to http://localhost/projectname/forms/abc.aspx

no xml declaration in the beginning

<?xml version="1.0"?>

也许是一些编码问题,文件开头的“unicode序列”或者这种性质的东西?

I had the same issue. It was caused because I handled exceptions in global.asax, and called Server.ClearError(), without calling a Response.Redirect or similar. I guess, that the code failed and the error was removed, so asp.net could not display an errormessage, nor could could it display the requested page.

I have also received this error, because I overrided the render method of the page, and forgot to call base.render(writer), thus sending an empty page to the browser.

I was facing the same issue. My solution may not apply to ASP.NET, I am working in node/express land. My API endpoint was not returning any data in the response:

return res.status(200).end();

When I included something in the data response it resolved the issue:

return res.status(200).send('ok').end();

嘿同样的错误发生在我身上,这个错误的解决方案是首先打开iis管理器,然后在服务器名称下的iis管理器中双击Web服务扩展,如果您的活动服务器页面被“禁止”,则将其更改为“允许”现在你的asp页面将运行。

There can be two reason for this. One you may have one or more unclosed HTML tag or you may have not set content type for our response. Read http://chiragrdarji.wordpress.com/2010/02/17/xml-parsing-error-no-element-found/ for more detail.

也许没有XML(XML是一个空白字符串)?

The site is developed in ASP.NET, not XML. Does this have any bearing on the problem?

I ran into this issue when installing my services on a fresh virtual machine. (ie; no other WCF services had been run on this machine, yet.)

You need to install and add a mapping for WCF Services into IIS. The easiest way to do this is as follows:

  1. Run a command prompt with elevated administrator privileges

  2. In the command prompt, navigate to C:\\Windows\\Microsoft.NET\\Framework\\v3.0\\Windows Communication Foundation

  3. Run the command ServiceModelReg.exe -i

  4. Restart IIS by running the command iisreset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM