?
Solved

UrlEncode & UrlDecode

Posted on 2003-10-24
5
Medium Priority
?
4,546 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 255 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 120 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

Technology Partners: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

800 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