Etc.
[Etc] Invalid XML Character 관련
INSPIEN
2013. 8. 5. 14:17
I/F 구현시 소스 시스템에서 생성한 데이터에 대해서 XML으로 매핑 전송 처리시 invalid XML character 또는 not well-formed 등의 에러 발생시 의심해볼만한 내용임
XML 표준에서는 아래와 같이 Character Range가 존재함 (xml version 1.0 기준 : http://www.w3.org/TR/2004/REC-xml-20040204/#NT-Char)
Character Range [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */ |
관련 범위외 문자를 제거는 webMethods의 경우 아래와 같이 서비스를 만들어서 처리 가능함
String IN_STR = IDataUtil.getString(pipeline.getCursor(), "IN_STR");
String OUT_STR = null;
String rtnMsg = null;
try{
if(IN_STR != null && IN_STR.length() > 0){
StringBuffer filteredString = new StringBuffer();
char current;
for (int i = 0; i < IN_STR.length(); i++) {
current = IN_STR.charAt(i);
if ((current == 0x9) || //
(current == 0xA) || //
(current == 0xD) || //
((current >= 0x20) && (current <= 0xD7FF)) || //
((current >= 0xE000) && (current <= 0xFFFD)) || //
((current >= 0x10000) && (current <= 0x10FFFF)))
{
filteredString.append(current);
}
}
OUT_STR = filteredString.toString();
}
}catch(Exception e){
rtnMsg = e.toString();
}
IDataUtil.put(pipeline.getCursor(),"OUT_STR", OUT_STR);
IDataUtil.put(pipeline.getCursor(),"rtnMsg", rtnMsg);