Solved

UrlEncode & UrlDecode

Posted on 2003-10-24
5
4,540 Views
Last Modified: 2012-05-04
I need to encode my data and decode so it can be stored in xml.
Thanks,
Dominik
0
Comment
Question by:Daij-Djan
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Assuming you are on Windows: To encode, use 'InternetCanonicalizeUrl()', to decode use 'InternetCrackUrl()' with the 'ICU_ESCAPE ' flag.
0
 
LVL 86

Accepted Solution

by:
jkr earned 85 total points
Comment Utility
0
 
LVL 5

Author Comment

by:Daij-Djan
Comment Utility
Isnt InternetCrackUrl using URL_COMMPONENTS? Isnt it overkill to also try to split the url.
Especially if it isnt vaild!?
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 40 total points
Comment Utility
It depends upon your needs (or rather the needs of the host to which you are passing data).  I use this simple fn to pass about 1500 bytes of XML to a host and I have been getting away with it for two years:

//-----------------------------------------------------------------------
// URL encoding of XML formdata
//
void DoUrlEncoding( CString& sXml )
{
      CString sRet, sTmp;
      int nLen= sXml.GetLength();
      for ( int j=0; j< nLen; j++ ) {
            char c= sXml[j];
            if ( isalnum(c) || c=='.' || c=='*' || c=='_' ) {
                  sRet+= c;
            }
            //------I was told must convert, but works in clear text
            else if ( c=='<') sRet += '<';
            else if ( c=='>') sRet += '>';
            else if ( c=='/') sRet += '/';
            else if ( c=='\"') sRet += '\"';
            // else if ( c==' ') sRet += ' ';          // I get away with this
            // else if ( c=='%') sRet += "%%";  // and this
            //----------------------------------
            else if ( c==' ') sRet += '+';      // output + for (space)
            else {
                  sTmp.Format( "%%%2.2X", c);     // output %NN (e.g., %C5 ) for other specials
                  sRet += sTmp;
            }
      }
      sXml= sRet;
}
0
 
LVL 5

Author Comment

by:Daij-Djan
Comment Utility
The host is an app that stores its data as xml.
I write a plugin for it and i need to encode the data it stores and then, also DECODE it once it is passed back to me.

BTW I am almost sure _I_ have to encode %, too...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now