Solved

URGENT: String Manipulation: Getting Rid of invalid characters for XML output

Posted on 2003-12-03
5
575 Views
Last Modified: 2013-12-03
I am trying to output an xml file that captures all of the subjects of e-mails.  However, in one of my e-mail subjects, I have the square character (the character that is displayed for an invalid character), and I want to replace all such characters with white space when outputting them to an XML file.  How can I accomplish this?  What characters are invalid for xml files?  the subjects are stored as char*
0
Comment
Question by:jjacksn
5 Comments
 
LVL 5

Author Comment

by:jjacksn
Comment Utility
I don't mind opening the stream after it has been written, rewritting the stream, and then removing all of the bad characters either.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Get all node texts and replace 0x0A (carriage return char), 0x0D (enter char), 0x3F (question mark char (?)) characters
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 166 total points
Comment Utility
>> square character (the character that is displayed for an invalid character),
That character just means that there is no glyph for the character code in the current font.  What you consider invalid may be perfectly valid if you display in a different font.

It is fairly easy to write code that reads an XML file and discards (or replaces with space) all characters that do not have glyphs in the a standard font, such as Arial or Courier.  Before generating the XML file, just trot each string through a function such as:

     Cleanup( char* p )  {
            while( *p != '\0') {
                  if ( (*p < ' ') || (*p > '~') ) {  // others if you want...
                       *p= ' '
                  }
                  p++;
            }
     }

-- Dan
0
 
LVL 5

Assisted Solution

by:rendaduiyan
rendaduiyan earned 166 total points
Comment Utility
try STL replace,
//suppose char* pszSubject is declared
vector<char> vSubject(pszSubject, pszSubject + strlen(pszSubject));
replace(vSubject.begin(), vSubject.end(), '[', ' ') ;
replace(vSubject.begin(), vSubject.end(), ']', ' ') ;
....
0
 
LVL 2

Accepted Solution

by:
xssass earned 168 total points
Comment Utility
hello,

You will get a square for non-printable characters. So you just have to filter them out... Theire ascii codes are below 32 and above 126. So the next code should work:

     Cleanup( char* p )  {
            while( *p != '\0') {
                  if ( (int(p) <= 31) || int(p) >= 127) {
                       *p= ' '
                  }
                  p++;
            }
     }

k.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 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.

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