Haxe and XML CDATA
Haxe does not properly read XML CDATA.
Considering the following XML:
<root>
<tag>
<![CDATA[foo]]>
</tag>
</root>
And the below Haxe snippet:
// `data` contains the above XML.
// Parses `data`.
var xml = haxe.xml.Fast(Xml.parse(data).firstElement());
We are unable to read the CDATA value of the tag
:
// Reads the inner data of `tag`
var content = xml.node.tag.innerData;
// > Exception is thrown!
// > 'tag does not only have data'
A simple fix is to trim the spaces before and after the CDATA element, then to parse the XML string:
// Normalize CDATA
data = ~/>\s+<!/gs.replace(data, "><!");
data = ~/]>\s+</gs.replace(data, "]><");
Written by Florent Cailhol
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Haxe
Authors
designerkamal
1.386K
ooflorent
1.368K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#