title: UrlEncode .net adds %00 characters at the end of the string
body: <p>When I urlEncode a string (namely a xml file) in some ocassions it adds %00 character at the end of the file. I'd like to know why it happens this and if it can be prevented (i can always erase the %00 characters). The xml file was created using xmlwriter. Weird thing is I use the same code to create other xml files and after encoding them it doesn't add %00 characters.</p>
  
  <p>Example: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;!DOCTYPE peticion &gt;
  &lt;peticion&gt;
      &lt;nombre&gt;Info hotel&lt;/nombre&gt;
      &lt;agencia&gt;HOTUSA&lt;/agencia&gt;
      &lt;tipo&gt;15&lt;/tipo&gt;
  &lt;/peticion&gt;
  </code></pre>
  
  <p>Edit: to create the xml this is what I do.</p>
  
  <pre><code>Dim xmlWriterSettings As New System.Xml.XmlWriterSettings
          With xmlWriterSettings
              .Encoding = Encoding.GetEncoding("iso-8859-1")
              .OmitXmlDeclaration = False
              .Indent = True
          End With
  
          Dim ms As New IO.MemoryStream
  
          Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(ms, xmlWriterSettings)
              With writer
                  .WriteDocType("peticion", Nothing, Nothing, Nothing)
                  .WriteStartElement("peticion")
                  .WriteElementString("nombre", "Info hotel")
                  .WriteElementString("agencia", "HOTUSA")
                  .WriteElementString("tipo", "15")
                  .WriteEndElement()
              End With
          End Using
  
          Dim xml As String = Encoding.GetEncoding("iso-8859-1").GetString(ms.GetBuffer)
  
  Dim XmlEncoded As String = HttpUtility.UrlEncode(xml)
  </code></pre>
  
  <p>XmlEncoded contains:</p>
  
  <pre><code>%3c%3fxml+version%3d%221.0%22+encoding%3d%22iso-8859-1%22%3f%3e%0d%0a%3c!DOCTYPE+peticion+%3e%0d%
  0a%3cpeticion%3e%0d%0a++%3cnombre%3eInfo+hotel%3c%2fnombre%3e%0d%0a++%3cagencia%3eHOTUSA%3c%
  2fagencia%3e%0d%0a++%3ctipo%3e15%3c%2ftipo%3e%0d%0a%3c%2fpeticion%3e%00%00%00%00%00%00%00%00%00%
  00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%
  00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%
  00%00%00%00%00%00%00%00%00%00%00%00%00%00
  </code></pre>
  
  <p>Where all these %00 come from?</p>