Here you can find the source of charArrayToXml(char[] input, int offset, int length)
Parameter | Description |
---|---|
input | the character array to convert |
offset | offset of the first character in the array subset to convert. |
length | the number of characters in the array subset. |
public static String charArrayToXml(char[] input, int offset, int length)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww. ja v a 2s.c o m * Converts a subset of a character array to XML string format. * @param input the character array to convert * @param offset offset of the first character in the array subset to convert. * @param length the number of characters in the array subset. * @return the XML representation of the character array subset. */ public static String charArrayToXml(char[] input, int offset, int length) { StringBuffer buf = new StringBuffer(); if (length < 0) { length = input.length; } else { length = offset + length; } if (length > input.length) { length = input.length; } for (int i = offset; i < length; i++) { char c = input[i]; if (c < 32 || c > 126) { buf.append(String.format("&#x%02X;", (int) c)); } else { switch (c) { case '&': buf.append("&"); break; case '<': buf.append("<"); break; case '>': buf.append(">"); break; case '"': buf.append("""); break; case '\'': buf.append("'"); break; default: buf.append(c); break; } } } return buf.toString(); } }