Only one top level element is allowed in an XML document.http://forums.asp.net/t/1688226.aspx/1?Only+one+top+level+element+is+allowed+in+an+XML+document+Fri, 10 Jun 2011 03:19:54 -040016882264452597http://forums.asp.net/p/1688226/4452597.aspx/1?Only+one+top+level+element+is+allowed+in+an+XML+document+Only one top level element is allowed in an XML document. <p>Hello,</p> <p>I have a webservice that returns an XML data but I get this error &quot;Only one top level element is allowed in an XML document. Error processing resource&quot;.</p> <p>I validate the xml using &quot;http://validator.w3.org/check&quot; and it was well formed but I still get the error above.</p> <p><strong>shoes.xml</strong></p> <pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt; &lt;shoes&gt; &lt;type&gt; &lt;name&gt;Nike&lt;/name&gt; &lt;stock&gt;166&lt;/stock&gt; &lt;/type&gt; &lt;type&gt; &lt;name&gt;Puma&lt;/name&gt; &lt;stock&gt;152&lt;/stock&gt; &lt;/type&gt; &lt;type&gt; &lt;name&gt;Sketchers&lt;/name&gt; &lt;stock&gt;310&lt;/stock&gt; &lt;/type&gt; &lt;/shoes&gt;</pre> <p><br /><strong>Webservice</strong></p> <pre class="prettyprint"> &lt;WebMethod()&gt; _ 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</pre> <p><strong>HomeController</strong></p> <pre class="prettyprint"> Public Function DisplayShoesInformation() As System.Xml.XmlElement Return IRepositoryWebService.myShoesInfo() End Function</pre> <p><strong>Index</strong></p> <pre class="prettyprint"> &#36;.get("/Home/DisplayShoesInformation", function (e) { &#36;(xml).find("shoes").each(function () { var test = &#36;(this).find("type").text(); alert(test); }); }, "xml");</pre> <p></p> <p>Thank You,</p> <p>-imperialx<strong><br> </strong></p> 2011-06-09T11:18:39-04:004452636http://forums.asp.net/p/1688226/4452636.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>Take a look at following links</p> <p><a target="_blank" href="../../../../t/1062792.aspx/1">http://forums.asp.net/t/1062792.aspx/1</a></p> <p><a target="_blank" href="http://www.webmasterworld.com/forum26/325.htm">http://www.webmasterworld.com/forum26/325.htm</a></p> 2011-06-09T11:40:21-04:004452640http://forums.asp.net/p/1688226/4452640.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>Set a breakpoint on webservice at this line &quot;</p> <pre class="prettyprint">Return doc.DocumentElement</pre> <pre class="prettyprint"><span class="pln"><br /></span></pre> <pre class="prettyprint"><span class="pln">Check the value returned and post here.</span></pre> 2011-06-09T11:44:33-04:004452641http://forums.asp.net/p/1688226/4452641.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> Take a look at following links</blockquote> <p></p> <p>Thanks for those links but I don't have any missing tags. <img src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-frown.gif" alt="Frown" title="Frown" border="0"></p> 2011-06-09T11:45:57-04:004452647http://forums.asp.net/p/1688226/4452647.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>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</p> <p>as suggested by <strong>tiagosalgado</strong> add a break point to your web service and check what exactly you are getting</p> 2011-06-09T11:49:23-04:004452651http://forums.asp.net/p/1688226/4452651.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tiagosalgado</h4> Check the value returned and post here.</blockquote> <p></p> <p>Hi tiagosalgado,</p> <p>There are quite a number of properties in there, which one should I post? <img src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-wink.gif" alt="Wink" title="Wink" border="0"></p> <p></p> <p>Thank You,</p> <p>-imperialx</p> 2011-06-09T11:51:37-04:004452717http://forums.asp.net/p/1688226/4452717.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p><strong>tiagosalgade</strong> is asking you to post value returned by</p> <pre class="prettyprint"><strong>return doc.</strong><strong>DocumentElement</strong> statement</pre> 2011-06-09T12:20:49-04:004452732http://forums.asp.net/p/1688226/4452732.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> <strong>tiagosalgade</strong> is asking you to post value</blockquote> <p></p> <p>sorry for the misinterpretation, here is the returned value.</p> <p><strong>{Element, Name=&quot;shoes&quot;}</strong></p> 2011-06-09T12:27:02-04:004452746http://forums.asp.net/p/1688226/4452746.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>Is the returned statement returning you just a single element</p> 2011-06-09T12:34:39-04:004452804http://forums.asp.net/p/1688226/4452804.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>imperialx</h4> <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> <strong>tiagosalgade</strong> is asking you to post value</blockquote> <p></p> <p>sorry for the misinterpretation, here is the returned value.</p> <p><strong>{Element, Name=&quot;shoes&quot;}</strong></p> <p></p> </blockquote> <p></p> <p>Hum, okey, so where do you get that error? On your webservice? Or on your javascript code?</p> 2011-06-09T13:12:00-04:004452873http://forums.asp.net/p/1688226/4452873.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tiagosalgado</h4> where do you get that error? On your webservice? Or on your javascript code?</blockquote> <p></p> <p>It's on the webservice. Did I correctly return a type of System.Xml.XmlElement or should it be on another type?</p> <p></p> 2011-06-09T13:40:07-04:004452888http://forums.asp.net/p/1688226/4452888.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>insted of xmlelement return string from there</p> 2011-06-09T13:45:10-04:004452908http://forums.asp.net/p/1688226/4452908.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> return string from there</blockquote> <p></p> <p>It returns a literal string &quot;<strong>System.Xml.XmlElement</strong>&quot;. <img title="Frown" border="0" alt="Frown" src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-frown.gif"></p> <pre class="prettyprint">&lt;WebMethod()&gt; _ Public Function myShoesInfo() As <strong>String</strong> Dim doc As New System.Xml.XmlDocument doc.Load(Server.MapPath(&quot;~/xml-files/shoes.xml&quot;)) Return doc.DocumentElement.<strong>ToString</strong> End Function</pre> 2011-06-09T13:56:30-04:004452922http://forums.asp.net/p/1688226/4452922.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>return the text inside <span class="pln">shoes.xml, i.e total xml as a string</span></p> 2011-06-09T14:04:02-04:004452936http://forums.asp.net/p/1688226/4452936.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>imperialx</h4> <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> return string from there</blockquote> <p></p> <p>It returns a literal string &quot;<strong>System.Xml.XmlElement</strong>&quot;. <img title="Frown" border="0" alt="Frown" src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-frown.gif"></p> <pre class="prettyprint">&lt;WebMethod()&gt; _ Public Function myShoesInfo() As <strong>String</strong> Dim doc As New System.Xml.XmlDocument doc.Load(Server.MapPath(&quot;~/xml-files/shoes.xml&quot;)) Return doc.DocumentElement.<strong>ToString</strong> End Function</pre> <p></p> </blockquote> <p></p> <p>Change to return doc.InnerXml;</p> <p></p> 2011-06-09T14:11:23-04:004452962http://forums.asp.net/p/1688226/4452962.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>devensawant</h4> return the text inside <span class="pln">shoes.xml</span></blockquote> <p></p> <p>sorry, but, how can i return the text from shoes.xml? I get this error&nbsp;'<strong>Invalid at the top level of the document</strong>'</p> <p>&nbsp;</p> <p><span color="#808080" size="2" face="Consolas" style="font-family:Consolas; color:#808080; font-size:x-small"><span color="#808080" size="2" face="Consolas" style="font-family:Consolas; color:#808080; font-size:x-small"><span color="#808080" size="2" face="Consolas" style="font-family:Consolas; color:#808080; font-size:x-small"></span></span></span></p> 2011-06-09T14:23:03-04:004452968http://forums.asp.net/p/1688226/4452968.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>return doc.InnerXml as suggested by&nbsp;<a title="tiagosalgado" href="../../../../members/tiagosalgado.aspx">tiagosalgado</a></p> 2011-06-09T14:24:29-04:004452973http://forums.asp.net/p/1688226/4452973.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>tiagosalgado</h4> <p></p> <p>Change to return doc.InnerXml;</p> <p></p> </blockquote> <p></p> <p>That part works, thanks!</p> <p>But if you look at&nbsp;code for the&nbsp;Index page above, no alert&nbsp;dialog&nbsp;box pops-up. <img title="Frown" border="0" alt="Frown" src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-frown.gif"></p> 2011-06-09T14:29:54-04:004452977http://forums.asp.net/p/1688226/4452977.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>Check out the below link for parsing xml using jQuery</p> <p><a target="_blank" href="http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery">http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery</a></p> 2011-06-09T14:32:54-04:004453002http://forums.asp.net/p/1688226/4453002.aspx/1?Re+Only+one+top+level+element+is+allowed+in+an+XML+document+Re: Only one top level element is allowed in an XML document. <p>Thank All for the help Guys! Appreciate it! <img title="Smile" border="0" alt="Smile" src="../../../../scripts/tiny_mce/plugins/emotions/img/smiley-smile.gif"></p> 2011-06-09T14:43:28-04:00