2009-05-29 1 views
1

CSV에서 데이터의 계층을 보존하는 것이 필수적인 XML 또는 JSON으로 데이터를 변환하는 것과 관련된 질문이 있습니다. 예를 들어.csv 파일을 xml 또는 json으로 변환 할 때 계층 구조 유지

, 나는이 같은 CSV 데이터가있는 경우 : 내가 원하는 것은 내가 같은 것을 얻을 수 있도록 XML의 계층 구조를 유지하는 것입니다

type,brand,country,quantity 
apple,golden_delicious,english,1 
apple,golden_delicious,french,2 
apple,cox,,4 
apple,braeburn,,1 
banana,,carribean,6 
banana,,central_america,7 
clememtine,,,3 

:

<fruit> 
<type = "apple"> 
<brand = "golden_delicious"> 
<country = "english" quantity = "1"> 
<country = "french" quantity = "2"> 
</brand> 
<brand = "cox"> 
<quantity = "4"> 
</brand> 
<brand = "braeburn"> 
<quantity = "1"> 
</brand> 
</type> 
<type = "banana"> 
<country = "carribean" quantity = "6"> 
<country = "central_america" quantity = "7"> 
</type> 
<type = "clementine"> 
<quantity = "3"> 
</type> 
<fruit /> 

가 가장 잘된다 JAXP를 사용하거나 위의 내용을 단순히 부모, 자식의 테이블로 변환 한 다음 데이터를 처리 할 문자열 배열에 씁니다. 이렇게 :

parent,child 
fruit,apple 
apple,golden_delicious 
golden_delicious,english 
golden_delicious,french 
english,1 
french,2 
apple,cox 
cox,4 
apple,braeburn 
braeburn,1 

등등.

더 좋은 방법이 있습니까?

감사

사이먼 레빈슨

csv로이 순서로 정렬되지 않은 경우 발생하는

답변

관련 문제