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

一种方法是使用内联 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 回答