我有一个xml文件,可能如下所示:
<unclassified>
WOOD FIRM FINED #30,000 OVER TEEN'S LOST ARM<
</unclassified>
.dtd声明:
<!ELEMENT unclassified (#PCDATA)>
不幸的是,这似乎不起作用,因为我总是会收到这样的错误:
[Fatal Error] arm1sub.sgml:14:46: The content of elements must consist of well-formed character data or markup.
org.xml.sax.SAXParseException; systemId: file:/home/sfalk/workspace/project/target/classes/meter_corpus/PA/annotated/courts/12.07.99/arm/arm1sub.sgml; lineNumber: 14; columnNumber: 46; The content of elements must consist of well-formed character data or markup.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205)
我该如何使这项工作?我希望在不操纵我的.xml文件的情况下这是可行的。
答案 0 :(得分:2)
您无法在DTD中更改任何内容来解决此问题。&#34; XML&#34;文件本身必须改变。 (从技术上讲,您的文档甚至不是XML。)
DTD(和XSD)的范围是验证,但XML有效的先决条件是格式良好。 (事实上,文档是XML的先决条件是格式正确。)
阅读Well-formed vs Valid XML以获得有关差异的详尽说明。对于您的特定问题,将<
替换为<
,以使您的XML 格式良好。
答案 1 :(得分:2)
如果要为xml解析器使用包含无效字符的值,可以使用CDATA:http://www.w3schools.com/xml/xml_cdata.asp
<unclassified>
<![CDATA[WOOD FIRM FINED #30,000 OVER TEEN'S LOST ARM<]]>
</unclassified>
或者你要低于你真正想要的......
<unclassified>
WOOD FIRM FINED #30,000 OVER TEEN'S LOST ARM
</unclassified>