[Fatal Error] temp_intermediate_result.xml:1:13: White space is required between the processing instruction target and data.
Intermediate XML is not valid:
org.xml.sax.SAXParseException; systemId: file:/Users/ipkuzne3/MTSProjects/vpnm/SchematronValidation/temp_intermediate_result.xml; lineNumber: 1; columnNumber: 13; White space is required between the processing instruction target and data.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:206)
at com.example.schematronvalidation.Validator.SchematronValidatorAPI.extractSchematronRules(SchematronValidatorAPI.java:116)
at com.example.schematronvalidation.Validator.SchematronValidatorAPI.main(SchematronValidatorAPI.java:28)
java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "
" is null
at com.helger.schematron.pure.SchematronResourcePure.fromString(SchematronResourcePure.java:530)
at com.example.schematronvalidation.Validator.SchematronValidatorAPI.validateXmlWithSchematron(SchematronValidatorAPI.java:150)
at com.example.schematronvalidation.Validator.SchematronValidatorAPI.main(SchematronValidatorAPI.java:31)
Я занимаюсь разработкой API для проверки XML по схеме xsd, но столкнулся с ошибкой: [code][Fatal Error] temp_intermediate_result.xml:1:13: White space is required between the processing instruction target and data. Intermediate XML is not valid: org.xml.sax.SAXParseException; systemId: file:/Users/ipkuzne3/MTSProjects/vpnm/SchematronValidation/temp_intermediate_result.xml; lineNumber: 1; columnNumber: 13; White space is required between the processing instruction target and data. at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:206) at com.example.schematronvalidation.Validator.SchematronValidatorAPI.extractSchematronRules(SchematronValidatorAPI.java:116) at com.example.schematronvalidation.Validator.SchematronValidatorAPI.main(SchematronValidatorAPI.java:28) java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because " " is null at com.helger.schematron.pure.SchematronResourcePure.fromString(SchematronResourcePure.java:530) at com.example.schematronvalidation.Validator.SchematronValidatorAPI.validateXmlWithSchematron(SchematronValidatorAPI.java:150) at com.example.schematronvalidation.Validator.SchematronValidatorAPI.main(SchematronValidatorAPI.java:31) [/code] Мой код: [code] private static String extractSchematronRules(String xsdFilePath) throws Exception { // Абсолютные пути к XSLT файлам String isoDSDLIncludePath = "src/main/resources/iso_dsdl_include.xsl"; String isoAbstractExpandPath = "src/main/resources/iso_abstract_expand.xsl"; String isoSVRLForXSLT2Path = "src/main/resources/iso_svrl_for_xslt2.xsl"; String skeletonPath = "src/main/resources/iso_schematron_skeleton_for_saxon.xsl";
// Проверка существования файлов if (!new File(isoDSDLIncludePath).exists()) { System.err.println("File not found: " + isoDSDLIncludePath); return null; } if (!new File(isoAbstractExpandPath).exists()) { System.err.println("File not found: " + isoAbstractExpandPath); return null; } if (!new File(isoSVRLForXSLT2Path).exists()) { System.err.println("File not found: " + isoSVRLForXSLT2Path); return null; } if (!new File(skeletonPath).exists()) { System.err.println("File not found: " + skeletonPath); return null; }
// Применение первого XSLT преобразования Transformer transformer = transformerFactory.newTransformer(new StreamSource(new FileInputStream(isoDSDLIncludePath))); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(xsdDocument), new StreamResult(writer)); String intermediateResult = writer.toString(); // System.out.println("Intermediate result after first transformation:"); // System.out.println(intermediateResult);
// Применение второго XSLT преобразования transformer = transformerFactory.newTransformer(new StreamSource(new FileInputStream(isoAbstractExpandPath))); writer = new StringWriter(); try { transformer.transform(new StreamSource(new StringReader(intermediateResult)), new StreamResult(writer)); intermediateResult = writer.toString(); System.out.println("Intermediate result after second transformation:"); System.out.println(intermediateResult); } catch (Exception e) { System.err.println("Error during second transformation:"); e.printStackTrace(); return null; }
// Удаление всех переводов строк из промежуточного результата intermediateResult = intermediateResult.replaceAll("\\s+", "");
// Очистка промежуточного XML-документа от некорректного контента intermediateResult = intermediateResult.trim(); int rootEndIndex = intermediateResult.lastIndexOf("