Hello,

I need to put XML fragments into another XML. Each time an XML fragment is put 
into another XML it needs to be escaped to be send to backend a java 
application. I used the function "CFXMLCreateStringByEscapingEntities" but it 
seems it can only escape an XML fragment once, the second time strange 
characters are added.

For this is wrote following method:

-(NSMutableString*)xmlEscape:(NSMutableString*)xmlString
{
        NSMutableString *aNSString = [NSMutableString 
stringWithString:xmlString];
        CFStringRef aCFString;
        CFStringRef bCFString;
        aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], 
NSUTF8StringEncoding);
        bCFString = CFXMLCreateStringByEscapingEntities(kCFAllocatorDefault, 
aCFString, NULL);

        NSMutableString *returnValue = [NSMutableString 
stringWithString:(NSMutableString*)bCFString];
        
        CFRelease(aCFString);
        CFRelease(bCFString);
        
        return returnValue;
}

The result is as follow:

First fragment:

<item type="Struct">
<item name="path">Links/lets&dance.jpg</item>
<item name="spread_index">0</item>
</item>
<item type="Struct">
<item name="path">Links/doubles_1/lets&dance.jpg</item>
<item name="spread_index">0</item>
</item>

Escaping this and put in a second fragment gives:

<item type="Struct">
<item name="level_id">4_2</item>
<item name="images" type="Array">&lt;item type=&quot;Struct&quot;&gt;
&lt;item name=&quot;path&quot;&gt;Links/lets&amp;dance.jpg&lt;/item&gt;
&lt;item name=&quot;spread_index&quot;&gt;0&lt;/item&gt;
&lt;/item&gt;
&lt;item type=&quot;Struct&quot;&gt;
&lt;item 
name=&quot;path&quot;&gt;Links/doubles_1/lets&amp;dance.jpg&lt;/item&gt;
&lt;item name=&quot;spread_index&quot;&gt;0&lt;/item&gt;
&lt;/item&gt;
</item>
</item>

Escaping this fragment again gives:

&lt;item type=&quot;Struct&quot;&gt;
&lt;item name=&quot;level_id&quot;&gt;4_2&lt;/item&gt;
&lt;item name=&quot;images&quot; type=&quot;Array&quot;&gt;قÄ-&amp;lt;قÄ،item 
typeقÄ-=&amp;quot;قÄ،StructقÄ-&amp;quot;&amp;gt;قÄ،
قÄ-&amp;lt;قÄ،item 
nameقÄ-=&amp;quot;قÄ،pathقÄ-&amp;quot;&amp;gt;قÄ،Links/lets&amp;amp;dance.jpgقÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
قÄ-&amp;lt;قÄ،item 
nameقÄ-=&amp;quot;قÄ،spread_indexقÄ-&amp;quot;&amp;gt;قÄ،0قÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
قÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
قÄ-&amp;lt;قÄ،item typeقÄ-=&amp;quot;قÄ،StructقÄ-&amp;quot;&amp;gt;قÄ،
قÄ-&amp;lt;قÄ،item 
nameقÄ-=&amp;quot;قÄ،pathقÄ-&amp;quot;&amp;gt;قÄ،Links/doubles_1قÄ-/قÄ،lets&amp;amp;dance.jpgقÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
قÄ-&amp;lt;قÄ،item 
nameقÄ-=&amp;quot;قÄ،spread_indexقÄ-&amp;quot;&amp;gt;قÄ،0قÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
قÄ-&amp;lt;/قÄ،itemقÄ-&amp;gt;قÄ،
&lt;/item&gt;
&lt;/item&gt;


Has anyone a solution for this problem?

Thanks a lot for your help.

Vit2Print.com NVTieltstraat 1678740 Pittem BelgiumPhone : +32 51 42 40 15Fax : 
+32 51 40 29 22Web : www.vit2print.com





___________________________________________________________________________
This e-mail, and any attachments thereto, is intended only for use by the 
addressee(s) named herein and may contain legally privileged and/or 
confidential information and/or information protected by intellectual property 
rights.
If you are not the intended recipient, please note that any review, 
dissemination, disclosure, alteration, printing, copying or transmission of 
this e-mail and/or any file transmitted with it, is strictly prohibited and may 
be unlawful.
If you have received this e-mail by mistake, please immediately notify the 
sender and permanently delete the original as well as any copy of any e-mail 
and any printout thereof.
We may monitor e-mail to and from our network.



<<inline: image/jpeg>>

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to