[英]Error: White spaces are required between publicId and systemId
I think I made mistakes in XML file in DOCTYPE line.我想我在 DOCTYPE 行的 XML 文件中犯了错误。 How can I solve my problem?
我该如何解决我的问题?
I using DOM library for parsing XML file.我使用 DOM 库来解析 XML 文件。 My XML file is named
firstTime.xml
:我的 XML 文件名为
firstTime.xml
:
<?xml version="1.0"?>
<!DOCTYPE tests PUBLIC "firstTime.xsd">
<tests xmlns="http://www.example.com/Report"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.com/Report firstTime.xsd">
<test id="1">
<coverage>65</coverage>
<usedFramework>Junit4</usedFramework>
<typeTest>Integration</typeTest>
</test>
<test id="2">
<coverage>35</coverage>
<usedFramework>Junit5</usedFramework>
<typeTest>Module</typeTest>
</test>
<test id="3">
<coverage>45</coverage>
<usedFramework>Mockito</usedFramework>
<typeTest>Integration</typeTest>
</test>
</tests>
My XSD file is named firstTime.xsd
:我的 XSD 文件名为
firstTime.xsd
:
<?xml version="1.0"?>
<xs:schema targetNamespace="http://www.example.com/Report"
xmlns="http://www.example.com/Report"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="tests">
<xs:complexType>
<xs:sequence>
<xs:element name="test" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="coverage" type="xs:positiveInteger"/>
<xs:element name="usedFramework" type="xs:string"/>
<xs:element name="typeTest" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My code using Java:我的代码使用 Java:
try {
File inputXml = new File(xmlPath);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
factory.setValidating(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inputXml);
}catch (ParserConfigurationException | IOException | SAXException e){
Logger.getLogger(XmlReader.class.getName()).log(Level.INFO,e.getMessage());
}
Error occurs when I'm trying to run java app:当我尝试运行 java 应用程序时发生错误:
after i changed xml file by adding this lines在我通过添加此行更改 xml 文件之后
<!DOCTYPE tests SYSTEM "firstTime.xsd">
<!DOCTYPE tests PUBLIC "1" "firstTime.xsd">
i recieve this error我收到这个错误
With PUBLIC
, you need two strings:使用
PUBLIC
,您需要两个字符串:
ExternalID ::= 'SYSTEM' S SystemLiteral
| 'PUBLIC' S PubidLiteral S SystemLiteral
See the XML Spec .请参阅XML 规范。
Alternative solutions:替代解决方案:
Strongly recommended: Delete the DOCTYPE
line;强烈建议:删除
DOCTYPE
行; it's rarely used with XSD.它很少与 XSD 一起使用。
Repair the DOCTYPE
line to be SYSTEM, and reference a DTD:将
DOCTYPE
行修复为 SYSTEM,并引用 DTD:
<.DOCTYPE tests SYSTEM "firstTime.dtd">
Repair the DOCTYPE
line to include both a publicId and a systemId, and reference a DTD:修复
DOCTYPE
行以包含 publicId 和 systemId,并引用 DTD:
<.DOCTYPE tests PUBLIC "your-public-id-here" "firstTime.dtd">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.