Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:40:42+00:00 2026-06-08T20:40:42+00:00

When I urlEncode a string (namely a xml file) in some ocassions it adds

  • 0

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.

Example:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE peticion >
<peticion>
    <nombre>Info hotel</nombre>
    <agencia>HOTUSA</agencia>
    <tipo>15</tipo>
</peticion>

Edit: to create the xml this is what I do.

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)

XmlEncoded contains:

%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

Where all these %00 come from?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:40:43+00:00Added an answer on June 8, 2026 at 8:40 pm

    The remarks on MemoryStream.GetBuffer provide the appropriate guidance:

    Note that the buffer contains allocated bytes which might be unused. For example, if the string “test” is written into the MemoryStream object, the length of the buffer returned from GetBuffer is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the ToArray method; however, ToArray creates a copy of the data in memory.

    Modify your code like so:

    Dim xml As String = Encoding.GetEncoding("iso-8859-1").GetString(ms.ToArray)
    

    In fact, a better option in this case would be to use a StringBuilder:

    Dim sb As New StringBuilder
    Using writer As XmlWriter = XmlWriter.Create(sb, xmlWriterSettings)
        ' ...
    End Using        
    
    Dim xml as String = sb.ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC controller method defined like this: public ActionResult GetPdf(string filename) {
I am Server.UrlEncode on some query string parameters and locally it is fine but
What would the difference be between: HttpUtility.UrlEncode(some string with é and β and stuff)
I have this bit of javascript: var jsonString = some string of json; $.post('proxy.php',
I need a library that can URLencode a string/char array. Now, I can hex
Why am I getting this error when trying to urlencode this string >>> callback
How can I urlencode a string with special chars æøå? ex. urllib.urlencode('http://www.test.com/q=testæøå') I get
Is there a kind of URLEncode in Groovy? I can't find any String →
I cannot request url http://www.besondere-raumdüfte.de with urllib2.urlopen(). I tried to encode string using urllib.urlencode
Server.UrlEncode(My File.doc) returns My+File.doc, whereas the javascript escape(My File.doc) returns My%20File.doc. As far as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.