[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

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

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
jjacksn
Asked:
jjacksn
3 Solutions
 
jjacksnAuthor Commented:
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
 
Roshan DavisCommented:
Get all node texts and replace 0x0A (carriage return char), 0x0D (enter char), 0x3F (question mark char (?)) characters
0
 
DanRollinsCommented:
>> 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
 
rendaduiyanCommented:
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
 
xssassCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now