.xlsx 파일에서 일부 문자열을 가져옵니다 (문자열은 단순 문자 임). 그런 다음 해당 문자열을 .xml 파일에 넣으려고합니다. 하지만 불행히도, 내가 'createElement (StringVariableHere)'메서드에 문자열을 넣을 때 다음 오류가 발생합니다 : "org.w3c.dom.DOMException : INVALID_CHARACTER_ERR : 잘못된 또는 잘못된 XML 문자가 지정되었습니다."엑셀 파일에서 .xml 파일로 문자열을 가져 오는 중 오류가 발생했습니다.
나는 이런 식으로 문자열 값을 얻을 :
switch (tempCell.getCellType()) {
case Cell.CELL_TYPE_STRING:
String tempColValue = tempCell.getStringCellValue();
}
을 그리고 이것은 내가 내 문자열 값을 추가 할 선이며 나에게 오류를 제공합니다.
Element titleChild = doc.createElement(StringVariableHere);
나는 심지어 내가 온라인으로 볼 수있는 다음과 같은 방법을 사용하여 문자열을 청소하려고 : 내가가 유효한지 아닌지를 확인하려면 다음을 사용하고 또한
public String stripNonValidXMLCharacters(String in) {
StringBuffer out = new StringBuffer(); // Used to hold the output.
char current; // Used to reference the current character.
if (in == null || ("".equals(in))) return ""; // vacancy test.
for (int i = 0; i < in.length(); i++) {
current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
if ((current == 0x9) ||
(current == 0xA) ||
(current == 0xD) ||
((current >= 0x20) && (current <= 0xD7FF)) ||
((current >= 0xE000) && (current <= 0xFFFD)) ||
((current >= 0x10000) && (current <= 0x10FFFF)))
out.append(current);
}
return out.toString();
}
을 때, 그리고 내가 내 문자열을 추가 false를 반환합니다.
XMLChar.isValidName(StringVariableHere)
시간 내 주셔서 감사합니다. 스테파노 스.
그래서 질문은 무엇인가? – djechlin