Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I can parse this XML like this :

XML
<pre lang="xml">
<item>
                    <title> <![CDATA[ TITLE ]]></title>
</item>
</pre>


But, I can't parse this XML like this :
XML
<item>
                    <title>
                    <![CDATA[ TITLE 
                    </title>                    
</item>



Please help me!
I'm using DOM Parser.
Thanks and best regard
Posted
Comments
[no name] 2-Nov-14 11:59am    
Because the second one is not valid....
http://www.w3schools.com/xml/xml_validator.asp[^]

Hi,

Try using XPATH...

title=xPath.evaluate("//item/title/text()", doc).trim();

Thanks,
Ullas Krishnan
 
Share this answer
 
1.First add this method
Java
public String getCharacterDataFromElement(Element e, String str) {
NodeList n = e.getElementsByTagName(str);   
Element e1=(Element) n.item(0);

Node child = e1.getFirstChild();
if (child instanceof CharacterData) {
  CharacterData cd = (CharacterData) child;
  return cd.getData();
}
return "";
}

2.Call the above method as so-
Java
map.put(KEY_DESC, parser.getCharacterDataFromElement(e, KEY_DESC));

This should get you the CDATA in String format. Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900