Android examples for XML:CDATA
add New Lines To XML CDATA Fields
/**/*from w ww . ja va 2 s.co m*/ * Created by IntelliJ IDEA. * User: Piek Vossen * Date: 17-dec-2008 * Time: 14:38:37 * To change this template use File | Settings | File Templates. * This file is part of KafSaxParser. KafSaxParser is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. KafSaxParser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with KafSaxParser. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String value = "java2s.com"; System.out.println(addNewLinesToFields1(value)); } public static String addNewLinesToFields1(String value) { String newValue = ""; int idx_s = 0; int idx_ts = value.indexOf("<"); int idx_tc = -1; int idx_te = -1; if (idx_ts > -1) { idx_te = value.indexOf("</", idx_ts); idx_tc = value.indexOf("<![CDATA[", idx_ts); if ((idx_tc > -1) && (idx_tc < idx_te)) { idx_ts = value.indexOf("]]>", idx_tc); if (idx_ts > -1) { idx_te = value.indexOf("</", idx_ts); } else { idx_te = -1; } } } // System.out.println("before loop"); while (idx_te != -1) { idx_te = value.indexOf(">", idx_te); newValue += value.substring(idx_s, idx_te + 1); newValue += "\n"; // System.out.println(newValue); idx_s = idx_te + 1; if (idx_s < value.length()) { idx_ts = value.indexOf("<", idx_te); if (idx_ts > -1) { idx_te = value.indexOf("</", idx_ts); idx_tc = value.indexOf("<![CDATA[", idx_ts); if ((idx_tc > -1) && (idx_tc < idx_te)) { idx_ts = value.indexOf("]]>", idx_tc); if (idx_ts > -1) { idx_te = value.indexOf("</", idx_ts); } else { idx_te = -1; } } } else { idx_te = -1; } } else { // break; } } if (idx_s < value.length()) { newValue += value.substring(idx_s); newValue += "\n"; } return newValue; } }