Solved

UrlEncode & UrlDecode

Posted on 2003-10-24
5
4,543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9615902
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
ID: 9615910
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 9617696
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
ID: 9619020
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
ID: 9619095
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 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