0

これ

<?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 (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'>
]>
4

1 に答える 1

1

これを行う 1 つの方法は、インライン DOCTYPE 宣言と外部エンティティを使用することです。これは、XML パーサーが DOCTYPE を処理できる場合にのみ役立ちます。

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

この場合data.txtは、xml ファイルの場所からの相対パスです。XML パーサーがそれに従うことができる場合は、絶対パスを使用することもできます。

于 2012-11-08T05:27:01.417 に答える