안녕하세요

프로그램 과정에서 막혔던 문제들에 대한 해결책 정리


페이지 목록

2014년 2월 19일 수요일

[XML] XML내의 특수 문자를 사용하게 해주는 문법

IBSheet는 기본적으로 MSXML을 사용하고 있습니다.

XML의 데이터 영역(PCDATA)에 특수문자를 사용하면 XML 오류가 발생합니다.
이때 특수 문자를 처리하는 방법은 두가지가 있습니다.

특수문자를 변환문자(이스케이프문자)로 변환하는 방법과 CDATA Section을 이용하는 방법입니다.

1. 변환문자(이스케이프문자)를 사용하는 방법
아래 변환문자는 게시판 표시 관계상 글자 사이 공백을 두었습니다.
& -> &
< -> &lt;
> -> &gt;
위 3가지 외에도 MSXML 2.0 이전에서는 아래 두문자도 같이 바꿔야 합니다.
' -> &apos;
" -> &quot;
예) 
XML : <TD>사장 &amp; 사원</TD>
결과 : 사장 & 사원

2. CDATA Section을 이용하는 방법
예) 
XML : <TD><![CDATA[사장 & 사원]]></TD>
결과 : 사장 & 사원

두가지 방법 모두 사용할수 있으나 IBSheet는 두번째 방법을 권장합니다.
첫번째 방법은 조회된 데이터 하나에 대해서 적어도 3번의 replace 조작이 필요하므로 그것보다는 특수문자를 그대로 사용하는 CDATA section 쪽이 조회속도를 더 빠르게 할수 있습니다.

출처: http://202psj.tistory.com/581

[XML] XML 형식으로 엑셀 파일 불러오기

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">

<Styles>
 <Style ss:ID="Default" ss:Name="Normal">
  <Alignment ss:Vertical="Bottom"/>
  <Borders/>
  <Font/>
  <Interior/>
  <NumberFormat/>
  <Protection/>
 </Style>
 <Style ss:ID="s27">
  <Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/>
 </Style>
 <Style ss:ID="s21">
  <NumberFormat ss:Format="yyyy\-mm\-dd"/>
 </Style>
 <Style ss:ID="s22">
  <NumberFormat ss:Format="yyyy\-mm\-dd\ hh:mm:ss"/>
 </Style>
 <Style ss:ID="s23">
  <NumberFormat ss:Format="hh:mm:ss"/>
 </Style>
</Styles>

 <Worksheet ss:Name="Sheet1">
  <ss:Table>
   <ss:Row>
    <ss:Cell  ss:StyleID="s27"><Data ss:Type="String">PID</Data></ss:Cell>
    <ss:Cell  ss:StyleID="s27"><Data ss:Type="String">JIRA_ID</Data></ss:Cell>
    <ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
<ss:Cell  ss:StyleID="s27"><Data ss:Type="String">Filepath</Data></ss:Cell>
   </ss:Row>
   <ss:Row>
    <ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
   </ss:Row>
   <ss:Row>
    <ss:Cell><Data ss:Type="Number">9300073</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-42</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String"></Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
   </ss:Row>
   <ss:Row>
    <ss:Cell><Data ss:Type="Number">9300159</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-41</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String"></Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">NCFTEST-40</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">코리아
df</Data></ss:Cell>
<ss:Cell><Data ss:Type="Number">9276614</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">2014-02-05 오후 12:23:37</Data></ss:Cell>
    <ss:Cell><Data ss:Type="String">N/A</Data></ss:Cell>
   </ss:Row>
  </ss:Table>
 </Worksheet>
</Workbook>

위 양식대로 작성을 하고 excel.xml 등 .xml 확장자 명으로 저장하면

위 내용이 excel 형식으로 나타나게 됩니다.