-
Notifications
You must be signed in to change notification settings - Fork 1
/
XmlCData.cls
28 lines (27 loc) · 1022 Bytes
/
XmlCData.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class XmlCData //not tested yet
{
//transform the cdata sections into regular nodes containing escaped text
public static String addCDataNodes(String XmlString)
{
Pattern CDataSectionPattern = Pattern.compile('<!\\[CDATA\\[(.*?)\\]\\]>');
Matcher m = CDataSectionPattern.matcher(XmlString);
while (m.find()) //could be simplified with a replaceAll ? @todo
{
XmlString = XmlString.substring(0, m.start()) +
'<CDataSection>'+
m.group(1).escapeXml() +
'</CDataSection>'
+ XmlString.substring( m.end());
m = CDataSectionPattern.matcher(XmlString);
}
return XmlString;
}
//read a node like getText
public static String text(Dom.XmlNode node)
{
Dom.XmlNode cdata = node.getChildElement('CDataSection', null);
if (cdata != null)
return cdata.getText().unescapeXml();
else return node.getText();
}
}