I am using an XML DOM Parser in my Activity and it has to parse XML with CDATA values. The DOM Parser works absolutely fine with plain XML, but when the data contains CDATA values it doesn’t work.
The XML file that I need to parse is like:
<?xml version="1.0" encoding="utf-8"?>
<organizations>
<organization>
<name><![CDATA[Center for Maximum]]></name>
<image><![CDATA[https://www.xyz.com/company_placeholder.png]]></image>
<city><![CDATA[Austin]]></city>
<state><![CDATA[Texas]]></state>
</organization>
</organizations>
I have added setCoalescing(true) to my DocumentBuilderFactory object but even then it is not parsing correctly. It is giving the error java.net.MalformedURLException: Protocol not found:. Thanks in advance.
Well the only solution that I found for this problem is to use XPATH for parsing the various item values. Such as, if we need to parse the “name” item in the above XML code then we need to do the following:
Now the String
namehas the desired value of the item “name”. This is the work around I used in my code for parsing CDATA. Hope this helps.