# RO : An invalid character was found in the text content

**URL:** https://talk.remobjects.com/t/ro-an-invalid-character-was-found-in-the-text-content/29128
**Category:** Remoting SDK
**Tags:** delphi
**Created:** [November 20, 2023, 4:41am UTC](https://talk.remobjects.com/t/ro-an-invalid-character-was-found-in-the-text-content/29128 "2023-11-20T04:41:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![wbjsoftwbjsoft](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wbjsoftwbjsoft](https://talk.remobjects.com/u/wbjsoftwbjsoft)
#### Post date: [November 20, 2023, 4:41am UTC](https://talk.remobjects.com/t/ro-an-invalid-character-was-found-in-the-text-content/29128/1 "2023-11-20T04:41:08Z")

</div>

I changed unit uROMSXMLImpl. please check source please.  
any performance issue in my code?

before:

```auto
procedure TROMSXMLNode.SetValue(const Value: Variant);
var
  s: UnicodeString;
begin
  s := VarToWideStrDef(Value, '');
  if isCDATA(s) then
    fNode.appendChild(fNode.ownerDocument.createCDATASection(ExtractCDATA(s)))
  else
    fNode.text := s;
end;

```

after:

```auto
procedure TROMSXMLNode.SetValue(const Value: Variant);
var
  s: UnicodeString;
  function StripUnwantedChar(Text: string):string;
  var
    NotAllowed: Set of Char;
    i, LeftOvers: Integer;
  begin
    NotAllowed := [#$1..#$8,#$E..#$1F,#$7F..#$84,#$86..#$9F];
    SetLength(Result, Length(Text));
    LeftOvers := 1;
    for i := 1 to Length(Text) do begin
      if not (Text[i] in NotAllowed) then begin
        Result[LeftOvers]:= Text[i];
        Inc(LeftOvers);
      end
    end;
    SetLength(Result, LeftOvers-1);
  end;
begin
  s := VarToWideStrDef(Value, '');
  if isCDATA(s) then
    fNode.appendChild(fNode.ownerDocument.createCDATASection(ExtractCDATA(s)))
  else
    fNode.text := StripUnwantedChar(s);
end;

```

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [November 20, 2023, 7:30am UTC](https://talk.remobjects.com/t/ro-an-invalid-character-was-found-in-the-text-content/29128/2 "2023-11-20T07:30:48Z")

</div>

Hi,

Your code is correct. You also may replace invalid chars with dot or space.

* * *

according to [Extensible Markup Language (XML) 1.1 (Second Edition)](https://www.w3.org/TR/xml11/#charsets), you can add also `#$B` and `#$C` chars:

> [#x1-#x8], [#xB-#xC], [#xE-#x1F], [#x7F-#x84], [#x86-#x9F], [#xFDD0-#xFDDF],  
> [#x1FFFE-#x1FFFF], [#x2FFFE-#x2FFFF], [#x3FFFE-#x3FFFF],  
> [#x4FFFE-#x4FFFF], [#x5FFFE-#x5FFFF], [#x6FFFE-#x6FFFF],  
> [#x7FFFE-#x7FFFF], [#x8FFFE-#x8FFFF], [#x9FFFE-#x9FFFF],  
> [#xAFFFE-#xAFFFF], [#xBFFFE-#xBFFFF], [#xCFFFE-#xCFFFF],  
> [#xDFFFE-#xDFFFF], [#xEFFFE-#xEFFFF], [#xFFFFE-#xFFFFF],  
> [#x10FFFE-#x10FFFF].
