2010-03-10 29 views
3

我解析了下面......org.xml.sax.SAXParseException:實體 「ndash的」 被引用,但沒有宣佈

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE tox:message SYSTEM "http://tox.sf.net/tox/dtd/tox.dtd"> 
<tox:message xmlns:tox="http://tox.sourceforge.net/"> 
<tox:model owner="scott" package="queue" function="appendFact"> 
<tox:parameter value=" By John Smith &ndash; Thu Feb 25, 4:54 pm ET&lt;br&gt;&lt;br&gt;NEW YORK (Reuters) &ndash; Nothing happened today."/> 
<tox:parameter value="10245"/> 
</tox:model> 
</tox:message> 

...使用saxon9.jar,但得到。 ..

org.xml.sax.SAXParseException: The entity "ndash" was referenced, but not declared. 

如何「聲明」一個實體進行解析?我將如何能夠預測所有潛在的實體?

回答

1

您在DTD聲明。由於您正在使用外部DTD,因此必須爲您申報。 tox.dtd是否包含ndash聲明?

如果沒有,你需要做一些啓發:

<!DOCTYPE foo [ 
    <!ENTITY % MathML SYSTEM "http://www.example.com/MathML.dtd"> 
    %MathML; 
    <!ENTITY % SpeechML SYSTEM "http://www.example.com/SpeechML.dtd"> 
    %SpeechML; 
]> 

你可以使用標準的XHTML的DTD定義ndash的,例如之一。

如果tox.dtd聲明瞭它,那麼你需要一個解析器來找到它。

相關問題