웹에서 읽어온 xml 데이터 자료를 Dom parser 를 통해 해석후 텍스트뷰에 보여줍니다.

이때 "&" 기호가 읽어올 데이터 문자열 사이에 있으면 텍스트뷰에 내용을 뿌려주지 못하네요.

 

서버에서 읽어오는 xml구조는 아래와 같습니다. (php로 mysql db에 있는 데이터를 가져와 xml형식으로 보내줍니다.)

여기서 내용이 들어가는 $comment 데이터를 텍스트뷰로 보여주는데 이때 문자열중에 "&" 기호가 있으면 텍스트뷰에

보여주지를 못합니다.

에러가 나는게 아니고 아예 데이터 해석을 못해서 뷰에 보여줄 데이터가 null이 됩니다.

무슨 문제일까요??? 로그를 통해 출력해보면 아래 데이터들은 다 정상적으로 넘어옵니다.

echo ("<? xml version='1.0' encoding='UTF-8' ?>");
echo ("<lists>"); 
echo ("
<data>
<rowid>$rowid</rowid>
<type>$type</type>
<category>$category</category>
<comment>$comment</comment>
<img>$img</img>
</data> 
"); 
echo ("</lists>");


아래부분이 가져온 xml 파싱 부분인데 잘못된 곳이 어떤것일까요??? 결국 여기 파싱하는 곳에서 "&"문자열이 있을경우 뭔가 문제가

있는 것 같은데요...

 public HashMap<String, String> xml2HashMap(String tmpData, String encoding) {  
  HashMap<String, String> hm = new HashMap<String, String>();
  hm.put("count", "0");   //레코드 수를 0으로 초기화
  try {
   /*
    * 전달받은 xml문서를 InputStream 형식으로 변환
    */
   DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();  
   DocumentBuilder docB = docBF.newDocumentBuilder();                       
   InputStream is = new ByteArrayInputStream(tmpData.getBytes(encoding));  
   Document doc = docB.parse(is);    
   /*
    * Dom parser를 통해 HashMap변환하여 기록
    */
   Element lists = doc.getDocumentElement();    
   NodeList dataList = lists.getElementsByTagName("data");  
   int c = 0;   //데이터 레코드 수를 계산하기 위해 변수 선언
   for (int i = 0; i < dataList.getLength(); i++) {      //data태그 갯수만큼 반복하며 내부 노드들 분석
    NodeList dataNodeList = dataList.item(i).getChildNodes();
    
    for (int j = 0; j < dataNodeList.getLength(); j++) {
     ;
     Node itemNode = dataNodeList.item(j);
 
     if (itemNode.getFirstChild() != null) {
      String nodeName = itemNode.getNodeName();
      String nodeValue = itemNode.getFirstChild().getNodeValue();
      hm.put(nodeName + "[" + i + "]", nodeValue);
     }
    }// for j
    c++;
   }// for i
   hm.put("count", Integer.toString(c));
  } catch (Exception e) {
   Log.i("InsertUploaderror", e.toString());
  }
  
  return hm;   
 }

 

임시방편으로 서버측에서 상기 데이터 취급시 "&"로된 문자가 입/출력 될적에는 무조건 "/" 기호로 변환을 시킨 상태인데

어떻게 해결책이 있을런지요???