2012-11-08 56 views
0

在這個如何插入從.txt文件文成XML文件

<?xml version="1.0" encoding="UTF-8" ?> 
    <!DOCTYPE Data (View Source for full doctype...)> 
- <Data> 
    <event start="Nov 5 2012 00:00:00 GMT" link="http://www.washingtonpost.com/wp-srv/onpolitics/watergate/chronology.htm" image="http://www.constitutioncenter.org/timeline/flash/assets/asset_upload_file761_12313.jpg" title="Nixon Elected">Richard Milhous Nixon, the 55-year-old former vice president who lost the presidency for the Republicans in 1960, reclaims it by defeating Hubert Humphrey in one of the closest elections in U.S. history</event> 
    <event start="June 17 2012 00:00:00 GMT" end="Aug 1 1972" link="http://www.washingtonpost.com/wp-srv/onpolitics/watergate/chronology.htm" image="http://www.utexas.edu/features/archive/2005/graphics/watergate4.jpg" title="Watergate arrests">Five men, one of whom says he used to work for the CIA, are arrested at 2:30 a.m. trying to bug the offices of the Democratic National Committee at the Watergate hotel and office complex.</event> 
    </Data> 

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE Data [ 
<!ENTITY data SYSTEM 'data.txt'> 
]> 
<Data> 
    &data; 
</Data> 

結果有反正過程中去除頂部線?或隱藏它們?

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE Data [ 
<!ENTITY data SYSTEM 'data.txt'> 
]> 
+1

解釋多一點。你只是將文件封裝在signle標籤中?你喜歡使用的工具嗎?我的意思是'echo「」>> file.xml; cat file.txt >> file.xml;回聲「」>> file.xml'將工作,但這可能不是你在之後。要指出的是,你需要解釋更多,並嘗試展示一些解釋你所嘗試的代碼。 – matchew

+0

謝謝。請檢查我的新增 – Dan

+0

好的,你在什麼環境下工作。* inx,windows,mac?你更喜歡做什麼工具?像oXygen這樣的xml編輯器,shell?蟒蛇? – matchew

回答

0

這樣做的一種方法是使用內聯DOCTYPE聲明和外部實體。這將不僅有助於但如果你的XML解析器能夠處理DOCTYPE

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE Data [ 
<!ENTITY data SYSTEM 'data.txt'> 
]> 
<Data> 
    &data; 
</Data> 

在這種情況下data.txt是從XML文件中的位置的相對路徑,你也可以使用絕對路徑,提供您的XML解析器可以跟隨它。