Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How to fix XmlTextReader closing connection unexpectedly?

xml connection

  • Please log in to reply
6 replies to this topic

#1 oujeboland

oujeboland

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 28 October 2011 - 07:11 AM

i want to change and save a html file at runtime using xmltextreader. it works fine on local host but after uploading website i get this error:

The underlying connection was closed: The connection was closed unexpectedly.

on:


File.Copy(source, pathToNewPost);

XmlTextReader txReader = new XmlTextReader(pathToNewPost);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(txReader);<------

  • 0

#2 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 28 October 2011 - 09:12 PM

I took time to blog about your post here
http://forum.codecal...expectedly.html
  • 0

#3 oujeboland

oujeboland

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 29 October 2011 - 12:15 AM

thx for paying attention,it doesn't work. the error :
Data at the root level is invalid
  • 0

#4 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 29 October 2011 - 01:49 AM

Please post the xml structure. I am pretty sure you got more than one element at the root level also have a look at this post .net - Why does C# XmlDocument.LoadXml(string) fail when an XML header is included? - Stack Overflow

Edited by gokuajmes, 29 October 2011 - 01:50 AM.
added SO link

  • 0

#5 oujeboland

oujeboland

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 29 October 2011 - 01:58 AM

this is a htm page that i want to copy it and then change it in my index.aspx page :
<!DOCTYPE html PUBLIC 
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">


    <title></title>
<link rel="Stylesheet"  href="../../indexpage.css" />    
    <meta  http-equiv="Content-Type" content="text/html; charset=UTF-8;"/>
    
    
    <div id="toolbar">
    <!--/*******************************************************************************************************/-->


<div id="cse-search-form" style="width:400px;float:right;margin-right:10px;">Loading</div>
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript"> 
  google.load('search', '1', {style : google.loader.themes.ESPRESSO});
  google.setOnLoadCallback(function() {
    var customSearchControl = new google.search.CustomSearchControl('007914246930950506745:hkhcj8dmbti');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    var options = new google.search.DrawOptions();
    options.setAutoComplete(true);
    options.enableSearchboxOnly("http://www.google.com/cse?cx=007914246930950506745:hkhcj8dmbti");
    customSearchControl.draw('cse-search-form', options);
  }, true);
</script>

<style type="text/css">
  input.gsc-input {
border:none;background:none;float:left;direction:rtl;
  }
  input.gsc-search-button {
background-image:url(../../images/btnsearch.gif);border-color:#cccccc;
width:80px;background-repeat:no-repeat;background-position:right;text-align:left;
  }
 

</style>


<!--/*******************************************************************************************************/-->


    </div>
    <br />
    <div id="header">

    </div>    
    <br />
    <div id="caption"></div>
    <div id="ads1" class="ads1">
    <img src="http://forum.codecall.net/../ads/ads1.gif" width="468" height="60" class="adsimages"/>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="468" height="60">
    <param name="movie" value="../../ads/ads1.swf" />
    <param name="quality" value="high"/>
    <embed  src="../../ads/ads1.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">
    </embed>
    </object>
    </div> 

    <div id="ads2" class="ads1">
    <img src="http://forum.codecall.net/../ads/ads2.gif" width="468" height="60"  class="adsimages"/>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="468" height="60">
    <param name="movie" value="../../ads/ads2.swf"/>
    <param name="quality" value="high"/>
    <embed  src="../../ads/ads2.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60"></embed>
    </object></div>
    <br />        
<script language="javascript" type="text/javascript" src="../../jquery-1.6.4.js"></script>     
<script language="javascript" type="text/javascript">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    function commitComment()
    { 
var jcommenter=document.getElementById('commenterName').value;
var jcontent=document.getElementById('comment').value;
var jpath=document.location.href; 
                    $.ajax({
                type: "POST",
                url: "../../jangalblog.asmx/addCommentAndChangePageSource",
                data: "{commenter:'"+jcommenter+"',content:'"+jcontent+"',pageAddress:'"+jpath+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError
            });
                }
    
            function OnSuccess(data, status)
            {
            //alert(data.d);
            if(data.d=='changed')
            window.location=window.location;
            //else{alert(data.d)}
            
            }

        function OnError(request, status, error)
         {
            alert(request.statusText);
         }
  
    $(document).ready(function()
    {
 var url=document.URL;
                        $.ajax({
                type: "POST",
                url: "../../privateWebserv.asmx/submitVisit",
                data: "{url:'"+url+"'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError
            });
    });
    
    
//    function submitVisiting()
//{
// var url=window.location;
//                        $.ajax({
//                type: "POST",
//                url: "../../../../privateWebserv.asmx/submitVisit",
//                data: "{url:'"+url+"'}",
//                contentType: "application/json; charset=utf-8",
//                dataType: "json",
//                success: OnSuccess,
//                error: OnError
//            });
// }
    </script>
</head>




<body onload="">




    <form id="form1" runat="server">  
    
    <br />

    <div id="leftside">
    <div id="ads3" class="ads3 ads4">
    <img src="http://forum.codecall.net/../ads/ads3.gif" width="120" height="240" class="adsimages"/>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" 
    width="120" height="240"><param name="movie" value="../../ads/ads3.swf"/>
    <param name="quality" value="high"/><embed  src="../../ads/ads3.swf"
     quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="240"></embed></object></div>
    <div id="ads4" class="ads3 ads6">
    <img src="http://forum.codecall.net/../ads/ads4.gif" width="120" height="240" class="adsimages"/>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0"
  width="120" height="240"><param name="movie" value="../../ads/ads4.swf"/><param name="quality" value="high"/>
  <embed  src="../../ads/ads4.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="240"></embed></object></div>
    <div id="ads5" class="ads3 ads6">
    <img src="http://forum.codecall.net/../ads/ads5.gif" width="120" height="240" class="adsimages"/>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" 
    width="120" height="240">
    <param name="movie" value="../../ads/ads5.swf"/><param name="quality" value="high"/>
    <embed  src="../../ads/ads5.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="240"></embed></object></div>
    <div id="ads6" class="ads3 ads6">
    <img src="http://forum.codecall.net/../ads/ads6.gif" width="120" height="240" class="adsimages"/>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0"
     width="120" height="240"><param name="movie" value="../../ads/ads6.swf"/>
     <param name="quality" value="high"/>
     <embed  src="../../ads/ads6.swf" quality="high" 
     pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="120" height="240"></embed></object></div>
    
    <br />
    
    
    </div>

    
    
    <div class="editor">
    
    <div id="post" class="contentDiv">
        
    <div id="postTitle"><a href="" id="postlink"><ptitle></ptitle></a></div>
    <br />
    <hr size="1" width="100px" style="float:right;"/>
    <br />
    <div id="postContent"><p id="postparagraph"><posttext></posttext></p></div>
    <br />
    <div id="postfooter">
    <username style="float:right;color:#888b97;font-family:Tahoma;font-size:small;"></username>
    <posttime style="float:left;color:#888b97;font-family:Tahoma;font-size:small;"></posttime>
    <postdate style="float:left;color:#888b97;font-family:Tahoma;font-size:small;"></postdate>
    
    </div>
    <br />
    <ul id="ulTag">
    <li id="liTag"><a href=""></a></li>
    </ul>
    <hr size="1" style="color:#eeeeee;width:300px;margin:auto;float:right;"/>
    <br />
    <div id="postComment">
    <label style="color:Gray;font-family:'B Jadid',arial,Tahoma;font-size:x-large;float:right;">نظرات</label>
    <br />
    <br />
    <commitedcomment>
    <ul id="ulComment">
    <li><label style="color:Blue;">نویسنده:</label><commitedcommenterName
     style="color:Gray;"></commitedcommenterName></li>    
    <br />
    <li><commitedcommentContent style="padding-right:10px;"></commitedcommentContent></li>
    <li><commitedcommentDate style="color:Gray;font-size:small;"></commitedcommentDate>
    <label> , </label><commitedcommentTime style="color:Gray;font-size:small;"></commitedcommentTime></li>
    <br />
    <hr size="1" style="color:#eeeeee;width:300px;margin:auto;float:right;"/>
    <br />
    </ul>
    </commitedcomment>
    
    </div>
    
    <div id="sendComment">
    <ul id="ulSendComment">
    <li> <label>نام:</label><input type="text" id="commenterName" class="textInput"/></li>
    <br /><br />
    <li> <label></label><textarea id="comment"></textarea></li>
    <br /><br />

    <li> 
<input type="button" class="btn" value="ثبت" onclick="commitComment()"/></li>
    </ul>
    <br />    <br />
    </div>
    
    <br />
    

    </div>
    
    </div>
    
    
    
    
    
        <div id="rightside">

        <div id="LPContainer2" class="LPContainer2">
    <div class="LPTL"></div>  
    <div class="LPTL LPTR"></div>
    <div class="sidecontent">  </div>
    <div class="LPTL LPBL"></div>
    <div class="LPTL LPBR"></div>
    </div>    
    
    
    <br />
    
        <div id="LPContainer" class="LPContainer">
    <div class="LPTL"></div>  
    <div class="LPTL LPTR"></div>
    <div class="sidecontent">  </div>
    <div class="LPTL LPBL"></div>
    <div class="LPTL LPBR"></div>
    </div>
    </div>

    
    

    </form>
    
<div id="footer" style="width:100%;height:50px;background-color:Black;clear:both;margin-top:50px;float:left;">

</div>

</body>

</html>




  • 0

#6 oujeboland

oujeboland

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 29 October 2011 - 10:30 PM

sorry i've posted my htm page codes but it seems that the post is not published here. anyway this is my htm page attached.
[ATTACH]4280[/ATTACH]

Attached Files


  • 0

#7 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 09 November 2011 - 05:53 AM

Actually just think with me. Do you think "HTML" is XML ? Certainly not, so definitely xmlTextReader can't read your html.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download