致命错误:temp_intermediate_result.xml:1:13:处理指令目标和数据之间需要空格。怎么解决?

问题描述 投票:0回答:1

我正在开发一个用于通过 xsd 方案验证 xml 的 API,但遇到错误:

[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 "<parameter1>" 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)

我的代码:

    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;
        }

        // Преобразование XSD в Schematron
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document xsdDocument;
        try (FileInputStream fis = new FileInputStream(xsdFilePath)) {
            xsdDocument = builder.parse(fis);
        }

        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        // Применение первого 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("</");
        if (rootEndIndex != -1) {
            intermediateResult = intermediateResult.substring(0, rootEndIndex + 2);
        }

        // Применение третьего XSLT преобразования с параметром sch.exslt.imports
        String tempXmlFilePath = "temp_intermediate_result.xml";
        try (FileWriter tempWriter = new FileWriter(tempXmlFilePath)) {
            tempWriter.write(intermediateResult);
        }

        // Проверка корректности промежуточного XML перед третьим преобразованием
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            db.parse(new File(tempXmlFilePath));
        } catch (Exception e) {
            System.err.println("Intermediate XML is not valid:");
            e.printStackTrace();
            return null;
        }

        transformXmlUsingXsl(tempXmlFilePath, isoSVRLForXSLT2Path);

        // Чтение итогового результата из временного файла
        String finalResult;
        try (FileInputStream tempFis = new FileInputStream("temp_final_result.xml")) {
            finalResult = new String(tempFis.readAllBytes(), StandardCharsets.UTF_8);
        }

        System.out.println("Final result after third transformation:");
        System.out.println(finalResult);
        return finalResult;
    }

XML:

<?xml version='1.0' encoding='UTF-8'?>
<Файл ИдФайл="ON_RISKNALMON_7700_7700_7710016640770701001_20241017_03fd95f3-ce5d-4ac3-9d4f-7a15e2ccfb22" ВерсПрог="Налогоплательщик ЮЛ" ВерсФорм="5.02">
  <Документ КНД="1125308" ДатаДок="17.10.2024" КодНО="7700" ГодНМ="2024" Период="31" НомерРед="1">
    <СвНП>
      <НПЮЛ НаимОрг="Публичное акционерное общество &quot;Московская городская телефонная сеть&quot;" ИННЮЛ="7710016640" КПП="770701001"/>
    </СвНП>
    <Подписант ПрПодп="2" Долж="Директор департамента">
      <ФИО Фамилия="Корнев" Имя="Дмитрий" Отчество="Александрович"/>
      <СвПред НаимДок="Доверенность б/н от 01.04.2021"/>
    </Подписант>
    <РискОргНМ ОКВЭД="61.10" ОблРиск="01.1" КодРиск="RISK001" НаимРиск="Неплатежные обязательства" ОписРиск="Невыполнение обязательств по кредитным договорам" НапрРиск="2201" КатегорРиск="1" КодНалог="012101" Статья="151" Пункт="1" Подпункт="-" Абзац="-" ВероятРиск="01" ПоследРиск="500000" УровРискОрг="1"/>
  </Документ>
</Файл>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2007 sp2 (http://www.altova.com) by VI (GNIVC FNS RF) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://purl.oclc.org/dsdl/schematron"
           xmlns:usch="http://www.unisoftware.ru/schematron-extensions"
           elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="Файл">
        <xs:annotation>
            <!---*******************************************************************************************************************************************************************************-->
            <xs:appinfo>
                <sch:pattern name="Проверка имени файла на соответствие значению атрибута @ИдФайл">
                    <sch:rule context="Файл">
                        <!--  1. Проверка имени файла на соответствие ИдФайл  -->
                        <sch:assert test="usch:getFileName() = @ИдФайл">
                            <usch:error code="0400400007" path="@ИдФайл" value-of-select="@ИдФайл" doc-id-path="usch:getFileName()" doc-id-caption="Файл">Имя файла обмена "<usch:value-of select="usch:getFileName()"/>" не совпадает со значением элемента ИдФайл "<usch:value-of select="@ИдФайл"/>"</usch:error>
                        </sch:assert>
                    </sch:rule>
                </sch:pattern>
            </xs:appinfo>
            <!---*******************************************************************************************************************************************************************************-->
            <xs:documentation>Файл обмена</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Документ">
                    <xs:annotation>
                        <xs:documentation>Состав и структура документа</xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="СвНП">
                                <xs:annotation>
                                    <xs:documentation>Сведения о налогоплательщике</xs:documentation>
                                </xs:annotation>
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="НПЮЛ">
                                            <xs:annotation>
                                                <xs:documentation>Сведения об организации - налогоплательщике</xs:documentation>
                                            </xs:annotation>
                                            <xs:complexType>
                                                <xs:attribute name="НаимОрг" use="required">
                                                    <xs:annotation>
                                                        <xs:documentation>Наименование организации - налогоплательщика (плательщика сбора, плательщика страховых взносов, налогового агента)</xs:documentation>
                                                    </xs:annotation>
                                                    <xs:simpleType>
                                                        <xs:restriction base="xs:string">
                                                            <xs:minLength value="1"/>
                                                            <xs:maxLength value="1000"/>
                                                        </xs:restriction>
                                                    </xs:simpleType>
                                                </xs:attribute>
                                                <xs:attribute name="ИННЮЛ" type="ИННЮЛТип" use="required">
                                                    <xs:annotation>
                                                        <xs:documentation>ИНН организации</xs:documentation>
                                                    </xs:annotation>
                                                </xs:attribute>
                                                <xs:attribute name="КПП" type="КППТип" use="required">
                                                    <xs:annotation>
                                                        <xs:documentation>КПП</xs:documentation>
                                                    </xs:annotation>
                                                </xs:attribute>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Подписант">
                                <xs:annotation>
                                    <!---*********************************************************************************************************************************************************-->
                                    <xs:appinfo>
                                        <sch:pattern name="Присутствие сведений о представителе">
                                            <sch:rule context="Подписант">
                                                <sch:assert test="usch:iif(@ПрПодп=2, count(СвПред)!=0, (count(СвПред)!=0 or count(СвПред)=0))">
                                                    <usch:error code="0400300003" path="@ПрПодп" value-of-select="@ПрПодп">Не выполнено условие присутствия (отсутствия) элемента Файл/Документ/Подписант/СвПред при значении элемента ПрПодп, равном "<usch:value-of select="@ПрПодп"/>".</usch:error>
                                                </sch:assert>
                                            </sch:rule>
                                        </sch:pattern>
                                    </xs:appinfo>
                                    <!---*********************************************************************************************************************************************************-->
                                    <xs:documentation>Сведения о лице, подписавшем документ</xs:documentation>
                                </xs:annotation>
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="ФИО" type="ФИОТип">
                                            <xs:annotation>
                                                <xs:documentation>Фамилия, имя, отчество руководителя организации (представителя организации)</xs:documentation>
                                            </xs:annotation>
                                        </xs:element>
                                        <xs:element name="СвПред" minOccurs="0">
                                            <xs:annotation>
                                                <xs:documentation>Сведения о представителе организации</xs:documentation>
                                            </xs:annotation>
                                            <xs:complexType>
                                                <xs:attribute name="НаимДок" use="required">
                                                    <xs:annotation>
                                                        <xs:documentation>Наименование и реквизиты документа, подтверждающего полномочия представителя организации</xs:documentation>
                                                    </xs:annotation>
                                                    <xs:simpleType>
                                                        <xs:restriction base="xs:string">
                                                            <xs:minLength value="1"/>
                                                            <xs:maxLength value="120"/>
                                                        </xs:restriction>
                                                    </xs:simpleType>
                                                </xs:attribute>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="ПрПодп" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Признак лица, подписавшего документ</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="1"/>
                                                <xs:enumeration value="1"/>
                                                <xs:enumeration value="2"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="Долж" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Должность</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="255"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="РискОргНМ" maxOccurs="unbounded">
                                <xs:annotation>
                                    <!---*********************************************************************************************************************************************************-->
                                    <xs:appinfo>
                                        <sch:pattern name="Присутствие элемента ОКВЭД">
                                            <sch:rule context="РискОргНМ">
                                                <sch:assert test="usch:iif(@КатегорРиск=2, count(@ОКВЭД)!=0, (count(@ОКВЭД)!=0 or count(@ОКВЭД)=0))">
                                                    <usch:error code="0400300003" path="@ОКВЭД" value-of-select="count(@ОКВЭД)">Не выполнено условие присутствия (отсутствия) элемента Файл/Документ/РискОргНМ/ОКВЭД при значении элемента КатегорРиск, равном "<usch:value-of select="@КатегорРиск"/>".</usch:error>
                                                </sch:assert>
                                            </sch:rule>
                                        </sch:pattern>
                                    </xs:appinfo>
                                    <!---*********************************************************************************************************************************************************-->
                                    <xs:documentation>Риски организации, идентифицируемые в целях налогового мониторинга</xs:documentation>
                                </xs:annotation>
                                <xs:complexType>
                                    <xs:attribute name="ОКВЭД" type="ОКВЭДТип" use="optional">
                                        <xs:annotation>
                                            <xs:documentation>Код вида экономической деятельности по ОКВЭД 2</xs:documentation>
                                        </xs:annotation>
                                    </xs:attribute>
                                    <xs:attribute name="ОблРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Область риска</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="4"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="КодРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Код риска организации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="50"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="НаимРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Наименование риска организации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="1000"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="ОписРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Описание риска организации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="1000"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="НапрРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Направление выявления риска</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="4"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="КатегорРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Категория риска</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="1"/>
                                                <xs:enumeration value="1"/>
                                                <xs:enumeration value="2"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="КодНалог" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Код налога</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="6"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="Статья" use="optional">
                                        <xs:annotation>
                                            <xs:documentation>Статья Налогового кодекса Российской Федерации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="10"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="Пункт" use="optional">
                                        <xs:annotation>
                                            <xs:documentation>Пункт статьи Налогового кодекса Российской Федерации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="10"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="Подпункт" use="optional">
                                        <xs:annotation>
                                            <xs:documentation>Подпункт пункта статьи Налогового кодекса Российской Федерации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="10"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="Абзац" use="optional">
                                        <xs:annotation>
                                            <xs:documentation>Абзац пункта (подпункта пункта) Налогового кодекса Российской Федерации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:minLength value="1"/>
                                                <xs:maxLength value="10"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="ВероятРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Вероятность возникновения риска</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="2"/>
                                                <xs:enumeration value="01"/>
                                                <xs:enumeration value="02"/>
                                                <xs:enumeration value="03"/>
                                                <xs:enumeration value="04"/>
                                                <xs:enumeration value="05"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="ПоследРиск" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Последствия риска (в тысячах рублей)</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:integer">
                                                <xs:totalDigits value="17"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="УровРискОрг" use="required">
                                        <xs:annotation>
                                            <xs:documentation>Уровень риска организации</xs:documentation>
                                        </xs:annotation>
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:length value="1"/>
                                                <xs:enumeration value="1"/>
                                                <xs:enumeration value="2"/>
                                                <xs:enumeration value="3"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="КНД" use="required">
                            <xs:annotation>
                                <xs:documentation>Код формы документа по КНД</xs:documentation>
                            </xs:annotation>
                            <xs:simpleType>
                                <xs:restriction base="КНДТип">
                                    <xs:enumeration value="1125308"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                        <xs:attribute name="ДатаДок" type="ДатаТип" use="required">
                            <xs:annotation>
                                <xs:documentation>Дата формирования документа</xs:documentation>
                            </xs:annotation>
                        </xs:attribute>
                        <xs:attribute name="КодНО" type="СОНОТип" use="required">
                            <xs:annotation>
                                <xs:documentation>Код налогового органа </xs:documentation>
                            </xs:annotation>
                        </xs:attribute>
                        <xs:attribute name="ГодНМ" type="xs:gYear" use="required">
                            <xs:annotation>
                                <xs:documentation>Период налогового мониторинга</xs:documentation>
                            </xs:annotation>
                        </xs:attribute>
                        <xs:attribute name="Период" use="required">
                            <xs:annotation>
                                <xs:documentation>Код периода документа</xs:documentation>
                            </xs:annotation>
                            <xs:simpleType>
                                <xs:restriction base="xs:string">
                                    <xs:length value="2"/>
                                    <xs:enumeration value="21"/>
                                    <xs:enumeration value="31"/>
                                    <xs:enumeration value="33"/>
                                    <xs:enumeration value="30"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                        <xs:attribute name="НомерРед" use="required">
                            <xs:annotation>
                                <xs:documentation>Порядковый номер редакции</xs:documentation>
                            </xs:annotation>
                            <xs:simpleType>
                                <xs:restriction base="xs:integer">
                                    <xs:totalDigits value="2"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="ИдФайл" use="required">
                <xs:annotation>
                    <xs:documentation>Идентификатор файла</xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1"/>
                        <xs:maxLength value="255"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="ВерсПрог" use="required">
                <xs:annotation>
                    <xs:documentation>Версия программы, с помощью которой сформирован файл</xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="40"/>
                        <xs:minLength value="1"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="ВерсФорм" use="required">
                <xs:annotation>
                    <xs:documentation>Версия формата</xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1"/>
                        <xs:maxLength value="5"/>
                        <xs:enumeration value="5.02"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="ФИОТип">
        <xs:annotation>
            <xs:documentation>Фамилия, имя, отчество</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Фамилия" use="required">
            <xs:annotation>
                <xs:documentation>Фамилия</xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:minLength value="1"/>
                    <xs:maxLength value="60"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="Имя" use="required">
            <xs:annotation>
                <xs:documentation>Имя</xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:minLength value="1"/>
                    <xs:maxLength value="60"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="Отчество" use="optional">
            <xs:annotation>
                <xs:documentation>Отчество</xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:minLength value="1"/>
                    <xs:maxLength value="60"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
    <xs:simpleType name="ИННЮЛТип">
        <xs:annotation>
            <xs:documentation>Идентификационный номер налогоплательщика - организации</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="10"/>
            <xs:pattern value="([0-9]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{8}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="КППТип">
        <xs:annotation>
            <xs:documentation>Код причины постановки на учет (КПП) - 5 и 6 знаки от 0-9 и A-Z</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="9"/>
            <xs:pattern value="([0-9]{1}[1-9]{1}|[1-9]{1}[0-9]{1})([0-9]{2})([0-9A-Z]{2})([0-9]{3})"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="КНДТип">
        <xs:annotation>
            <xs:documentation>Код из Классификатора налоговой документации</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="7"/>
            <xs:pattern value="[0-9]{7}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="СОНОТип">
        <xs:annotation>
            <xs:documentation>Коды из Классификатора системы обозначений налоговых органов</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="4"/>
            <xs:pattern value="[0-9]{4}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="КБКТип">
        <xs:annotation>
            <xs:documentation>Код из Классификатора доходов в бюджет </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="20"/>
            <xs:pattern value="[0-9]{20}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="ОКВЭДТип">
        <xs:annotation>
            <xs:documentation>Код из Общероссийского классификатора видов экономической деятельности</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:maxLength value="8"/>
            <xs:minLength value="2"/>
            <xs:pattern value="[0-9]{2}"/>
            <xs:pattern value="[0-9]{2}\.[0-9]{1}"/>
            <xs:pattern value="[0-9]{2}\.[0-9]{2}"/>
            <xs:pattern value="[0-9]{2}\.[0-9]{2}\.[0-9]{1}"/>
            <xs:pattern value="[0-9]{2}\.[0-9]{2}\.[0-9]{2}"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="ДатаТип">
        <xs:annotation>
            <xs:documentation>Дата в формате ДД.ММ.ГГГГ (01.01.1900 - 31.12.2099)</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:length value="10"/>
            <xs:pattern value="(((0[1-9]{1}|[1-2]{1}[0-9]{1})\.(0[1-9]{1}|1[0-2]{1}))|((30)\.(01|0[3-9]{1}|1[0-2]{1}))|((31)\.(01|03|05|07|08|10|12)))\.(19[0-9]{2}|20[0-9]{2})"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

取自 schematron 的 github 存储库:https://github.com/Schematron/schematron/tree/master/trunk/schematron/code

也许有人已经实现了类似的东西,请告诉我如何解决这个问题。

最终,我们应该获得一个使用 xcd 方案验证 xml 的自动化 API,xsl 文件将从 S3 服务器获取,参数将接受两个多部分文件:xsd 和 xml。

java xml xslt-2.0 xml-validation schematron
1个回答
0
投票

通过堆栈跟踪判断

java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "<parameter1>" 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)

在你的类中

com.example.schematronvalidation.Validator.SchematronValidatorAPI
调用
SchematronResourcePure.fromString()
,你传递两个参数:schematron和字符集,问题是这个charset为null

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.