java - Empty the textcontent between the tags in xml -
i tried parse below xml using dom parser. error thrown while parsing xml. because of special characters present inside cdata tag of 'b' element. need text content of c , e elements. trying empty of 'b' element , use indexof function text content of both c , e elements.
   <a><b><![cdata[userinput]]></b><c>text of c</c><d></d><e>text of e</e></a> below code using pattern matching
pattern pattern = pattern.compile("<b>.*?</b>", pattern.dotall |  pattern.unicode_case | pattern.multiline); matcher matcher = pattern.matcher(input); stringbuilder builder = new stringbuilder(); int lastindex = 0; while (matcher.find()) {     builder.append(input.substring(lastindex, matcher.start()));     lastindex = matcher.end(); } builder.append(input.substring(lastindex)); below scenerio failing above pattern
 <a><b><![cdata[test 123 </b><c>inside</c>]]></b><c>outside</c><d></d><e>out side</e></a> o/p:-
 <a><c>inside</c>]></b><c>outside</c><d></d><e>out side</e></a> expected :-
<a><c>outside</c><d></d><e>out side</e></a> could please let me know best way resolve issue. user input might choice of text user.
thanks in advance gajendra
try it:
string output = input.replaceall("<b>.*</b>", ""); 
Comments
Post a Comment