开发者

More XML Problems - Undeclared Entity 'nbsp'

I'm getting the error:

Line 49: xml = r.ReadToEnd(); Line 50: Line 51: System.Xml.Linq.XDocument xmlDoc = System.Xml.Linq.XDocument.Parse(xml); Line 52:

Line 53: var query = from p in xmlDoc.Descendants("member")

On my XML. When I run the code to generate the XML in an empty page, it runs without error, if I call the code within my webpage it throws this error. The only 'nbsp' on the page is a doctype declaration at the top of the XSLT:

<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>

I'm at a loss as to where this error is coming from and I am looking for suggestions please!

Thanks.

Here is the C# code that pulls 开发者_StackOverflow社区in the XML:

protected void exportList(Object sender, EventArgs e)
    {
        String gid;
        gid = Request.QueryString["gid"].ToString();
        //XElement xml = XElement.Load("/members/listmembersxmlfeed?gid=" + gid);

        String xml = String.Empty;

        System.Net.WebResponse WR = System.Net.WebRequest.Create(Request.Url + "/members/listmembersxmlfeed?gid=" + gid).GetResponse();

        System.IO.StreamReader r = new System.IO.StreamReader(WR.GetResponseStream());
        xml = r.ReadToEnd();

        System.Xml.Linq.XDocument xmlDoc = System.Xml.Linq.XDocument.Parse(xml);

            var query = from p in xmlDoc.Descendants("member")
                    select new
                    {
                        Name = p.Element("name").Value,
                        Email = p.Element("email").Value
                    };

            foreach (var member in query)
            {
                    Response.Write("Employee: " + member.Name + " " + member.Email + "<br />");
            }
    }

Hope this help.


Your XML document must have a DTD declaring the @nbsp; entity:

<!DOCTYPE topElementName [ <!ENTITY nbsp "&#x00A0;"> ]> 

Otherwise the text is not a wellformed XML document (containes undefined entity), which the error message is telling you.

The fact that the XSLT stylesheet has this declaration is good only for the XSLT stylesheet. Such declaration is also needed separately for the XML document,


Changed the WebRequest.Create to a static URL instead of Request.Uri + "/listmembersxmlfeed?gid=" + gid, which solved it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜