I have a webservice that returns an XML data but I get this error "Only one top level element is allowed in an XML document. Error processing resource".
I validate the xml using "http://validator.w3.org/check" and it was well formed but I still get the error above.
<WebMethod()> _
Public Function myShoesInfo() As System.Xml.XmlElement
Dim doc As New System.Xml.XmlDocument
doc.Load(Server.MapPath("~/xml-files/shoes.xml"))
Return doc.DocumentElement
End Function
HomeController
Public Function DisplayShoesInformation() As System.Xml.XmlElement
Return IRepositoryWebService.myShoesInfo()
End Function
Index
$.get("/Home/DisplayShoesInformation", function (e) {
$(xml).find("shoes").each(function () {
var test = $(this).find("type").text();
alert(test);
});
}, "xml");
Yes i have seen that your xml dont have any problem, but have read that links properly, there is a possibility that before returning the xml string it is getting altered/changed somewhere
as suggested by tiagosalgado add a break point to your web service and check what exactly you are getting
imperialx
Member
523 Points
1222 Posts
Only one top level element is allowed in an XML document.
Jun 09, 2011 11:18 AM|LINK
Hello,
I have a webservice that returns an XML data but I get this error "Only one top level element is allowed in an XML document. Error processing resource".
I validate the xml using "http://validator.w3.org/check" and it was well formed but I still get the error above.
shoes.xml
<?xml version="1.0" encoding="iso-8859-1" ?> <shoes> <type> <name>Nike</name> <stock>166</stock> </type> <type> <name>Puma</name> <stock>152</stock> </type> <type> <name>Sketchers</name> <stock>310</stock> </type> </shoes>Webservice
<WebMethod()> _ Public Function myShoesInfo() As System.Xml.XmlElement Dim doc As New System.Xml.XmlDocument doc.Load(Server.MapPath("~/xml-files/shoes.xml")) Return doc.DocumentElement End FunctionHomeController
Public Function DisplayShoesInformation() As System.Xml.XmlElement Return IRepositoryWebService.myShoesInfo() End FunctionIndex
$.get("/Home/DisplayShoesInformation", function (e) { $(xml).find("shoes").each(function () { var test = $(this).find("type").text(); alert(test); }); }, "xml");Thank You,
-imperialx
devensawant
Contributor
3763 Points
858 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 11:40 AM|LINK
Take a look at following links
http://forums.asp.net/t/1062792.aspx/1
http://www.webmasterworld.com/forum26/325.htm
If my post helps you then please mark as answer
tiagosalgado
Contributor
2410 Points
544 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 11:44 AM|LINK
Set a breakpoint on webservice at this line "
Check the value returned and post here.http://geekswithblogs.com/TiagoSalgado
@TiagoSalgado
imperialx
Member
523 Points
1222 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 11:45 AM|LINK
Thanks for those links but I don't have any missing tags.
devensawant
Contributor
3763 Points
858 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 11:49 AM|LINK
Yes i have seen that your xml dont have any problem, but have read that links properly, there is a possibility that before returning the xml string it is getting altered/changed somewhere
as suggested by tiagosalgado add a break point to your web service and check what exactly you are getting
If my post helps you then please mark as answer
imperialx
Member
523 Points
1222 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 11:51 AM|LINK
Hi tiagosalgado,
There are quite a number of properties in there, which one should I post?
Thank You,
-imperialx
devensawant
Contributor
3763 Points
858 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 12:20 PM|LINK
tiagosalgade is asking you to post value returned by
If my post helps you then please mark as answer
imperialx
Member
523 Points
1222 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 12:27 PM|LINK
sorry for the misinterpretation, here is the returned value.
{Element, Name="shoes"}
devensawant
Contributor
3763 Points
858 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 12:34 PM|LINK
Is the returned statement returning you just a single element
If my post helps you then please mark as answer
tiagosalgado
Contributor
2410 Points
544 Posts
Re: Only one top level element is allowed in an XML document.
Jun 09, 2011 01:12 PM|LINK
Hum, okey, so where do you get that error? On your webservice? Or on your javascript code?
http://geekswithblogs.com/TiagoSalgado
@TiagoSalgado