简体   繁体   English

错误:publicId 和 systemId 之间需要空格

[英]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:替代解决方案:

  1. Strongly recommended: Delete the DOCTYPE line;强烈建议:删除DOCTYPE行; it's rarely used with XSD.它很少与 XSD 一起使用。

  2. Repair the DOCTYPE line to be SYSTEM, and reference a DTD:DOCTYPE行修复为 SYSTEM,并引用 DTD:

     <.DOCTYPE tests SYSTEM "firstTime.dtd">
  3. 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">

See also也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 publicId和systemId之间必须有空格 - White spaces are required between publicId and systemId publicId 和 systemId 之间需要空格 - White spaces are required between publicId and systemId 解析KML文档时,publicId和systemId之间需要空格 - White spaces are required between publicId and systemId while parsing KML document org.xml.sax.SAXParseException; publicId和systemId之间必须有空格 - org.xml.sax.SAXParseException; White spaces are required between publicId and systemId Java:如何防止EntityResolver中的&#39;systemId&#39;#resolveEntity(String publicId,String systemId)从绝对化到当前工作目录 - Java: How to prevent 'systemId' in EntityResolver#resolveEntity(String publicId, String systemId) from being absolutized to current working directory 如何读取空格之间的整数? - How to read integers between white spaces? 扫描较大的文本,并在行与行之间留空格 - Scanning a larger text with white spaces between lines 页面显示单词和行之间没有输入或空白 - Page shows no enters or white spaces between words and lines 字符串中单词之间多余的空格的正则表达式条件 - Regex condition for extra white spaces between words in a string 正则表达式在字符串之间以及空格之间获取字符串 - Regex get string after string and between white spaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM