일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- LCHF
- 부업추천
- Ai
- 다이어트 후기
- #시그널
- 한식레시피
- 키토제닉
- 진마켓
- 머니로그
- Koreanfood
- 안드로이드
- 자동차세연납
- 간단요리
- 정자동맛집
- 고지방 다이어트
- Android
- 브롤스타즈
- 남아공월드컵
- 트레이더스
- 집밥레시피
- 부산맛집
- 대한민국
- 고지방다이어트
- 재테크팁
- 갤럭시S
- 키토제닉 다이어트
- 저탄고지
- 2025자동차세
- 저탄수 다이어트
- 다이어트 식단
- Today
- Total
머니로그
XML : invalid characters 본문
XML 기반으로 작업하는 과정에서 유니코드의 특정 Character을 사용하는 경우
[XMLObject] unmarshal An invalid XML Character ( Unicode : 0x1 ) was found in the element content o the document.
등과 같은 유사한 문제가 발생할 수 있다.
예를 들면, 와 같은 문자이다. 이는 소문자 r 이 아닌 Unicode을 포함되는 다른 특정 문자입니다.
아래는 invalid character을 제거하는 소스 이다.
http://cse-mjmcl.cse.bris.ac.uk/blog/2007/02/14/1171465494443.html
/**
* This method ensures that the output String has only valid
* XML unicode characters as specified by the XML 1.0 standard.
* For reference, please see the
* standard. This method will return an empty String if the input is null or empty.
*
* @author Donoiu Cristian, GPL
* @param The String whose non-valid characters we want to remove.
* @return The in String, stripped of non-valid characters.
*/
public static String removeInvalidXMLCharacters(String s) {
// Used to hold the output.
StringBuilder out = new StringBuilder();
// Used to reference the current character.
int codePoint;
//This is actualy one unicode character, represented by two code units!!!.
//String ss = "\ud801\udc00";
//System.out.println(ss.codePointCount(0, ss.length()));// See: 1
int i=0;
while(i<s.length()) {
System.out.println("i=" + i);
//This is the unicode code of the character.
codePoint = s.codePointAt(i);
// Consider testing larger ranges first to improve speed.
if ((codePoint == 0x9) ||
(codePoint == 0xA) ||
(codePoint == 0xD) ||
((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) {
out.append(Character.toChars(codePoint));
}
// Increment with the number of code units(java chars)
// needed to represent a Unicode char.
i+= Character.charCount(codePoint);
}
return out.toString();
}
내용을 확인해 보면 Unicode 0x20 이전에는 0x9, 0xA, 0xD 을 제외한 값들은 사용할 수 없는 것을 뜻합니다.
* 그 외 처리 방법
Debug.WriteLine(reg.Replace(str," "));
'과거기록 (2010 ~ 2024) > IT' 카테고리의 다른 글
캡쳐 프로그램, "오픈 캡쳐" (0) | 2010.06.24 |
---|---|
알송 다운로드 (0) | 2010.06.24 |
Unicode ( 유니코드 ) (0) | 2010.06.23 |
Google Docs (0) | 2010.06.23 |
[알집] 알집 다운로드 및 설치방법 (0) | 2010.06.22 |