【发布时间】:2015-07-16 15:25:42
【问题描述】:
我想解析 xml 字符串。这是我的java代码:
public Document loadXMLFromString(String xml) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
return builder.parse(is);
}
但是在解析的时候,遇到了这个异常:
[Fatal Error] nitf-3-3.dtd:1:3: The markup declarations contained or pointed to by the document type declaration must be well-formed.
我无法弄清楚为什么会发生此异常。我认为它可能涉及“nitf”。有人可以帮帮我吗?
这是我的 xml 字符串:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE nitf SYSTEM "http://www.nitf.org/IPTC/NITF/3.3/specification/dtd/nitf-3-3.dtd">
<nitf change.date="June 10, 2005" change.time="19:30" version="-//IPTC//DTD NITF 3.3//EN">
<head>
<title>Dr. Nina M. Hill To Wed in April</title>
<meta content="1" name="publication_day_of_month"/>
<meta content="1" name="publication_month"/>
<meta content="1989" name="publication_year"/>
<meta content="Sunday" name="publication_day_of_week"/>
<meta content="Society Desk" name="dsk"/>
<meta content="39" name="print_page_number"/>
<meta content="1" name="print_section"/>
<meta content="1" name="print_column"/>
<meta content="Style" name="online_sections"/>
<docdata>
<doc-id id-string="210943"/>
<doc.copyright holder="The New York Times" year="1989"/>
<identified-content>
<classifier class="indexing_service" type="descriptor">WEDDINGS AND ENGAGEMENTS</classifier>
<person class="indexing_service">HILL, NINA MARIE</person>
<person class="indexing_service">FRANCIS, WALTER</person>
<classifier class="online_producer" type="taxonomic_classifier">Top/Features/Style</classifier>
<classifier class="online_producer" type="taxonomic_classifier">Top/Features/Style/Fashion and Style</classifier>
<classifier class="online_producer" type="taxonomic_classifier">Top/Features/Style/Fashion and Style/Weddings and Celebrations</classifier>
<classifier class="online_producer" type="general_descriptor">Weddings and Engagements</classifier>
</identified-content>
</docdata>
<pubdata date.publication="19890101T000000" ex-ref="http://query.nytimes.com/gst/fullpage.html?res=950DEEDE1730F932A35752C0A96F948260" item-length="180" name="The New York Times" unit-of-measure="word"/>
</head>
<body>
<body.head>
<hedline>
<hl1>Dr. Nina M. Hill To Wed in April</hl1>
</hedline>
</body.head>
<body.content>
<block class="lead_paragraph">
<p>LEAD: The engagement of Dr. Nina Marie Hill to Walter Francis Raquet, the son of Mr. and Mrs. Peter Raquet of Tequesta, Fla., has been made known by her parents, Ilda Kleiner of Delray Beach, Fla., and Peter Hill of New York. The couple plan to marry in April.</p>
</block>
<block class="full_text">
<p>LEAD: The engagement of Dr. Nina Marie Hill to Walter Francis Raquet, the son of Mr. and Mrs. Peter Raquet of Tequesta, Fla., has been made known by her parents, Ilda Kleiner of Delray Beach, Fla., and Peter Hill of New York. The couple plan to marry in April.</p>
<p>Mr. Raquet is the senior vice president for marketing and new products at Herzog, Heine, Geduld, market makers for over-the-counter stocks and bonds in New York. He graduated from New York University. His father is a retired investor.</p>
</block>
</body.content>
</body>
</nitf>
【问题讨论】:
-
看来
XML不符合指定的DTD。 -
我认为您的 xml 文件格式不正确,请参阅 stackoverflow.com/q/15588090/4793343