未找到DTD / Schema声明

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

这是我从这里获得的示例XML:http://www.statistik.at/GBS-Schema/Beispiel/LHD-V55-Monat-Beispiel.xml

<?xml version="1.0" encoding="UTF-8"?>
<lhd:kennsatz   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:lhd="http://www.statistik.gv.at/LHD-V55/Schema"
                xsi:schemaLocation="http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd">
    <lhd:finanzjahr>2020</lhd:finanzjahr>
    <lhd:quartal>0</lhd:quartal>
    <lhd:monat>12</lhd:monat>
    <lhd:regkz>3</lhd:regkz>
    <lhd:periode>m</lhd:periode>
    <lhd:bundesland>Tirol</lhd:bundesland>
    <lhd:verantwortlich>max Hasenfuß</lhd:verantwortlich>
    <lhd:sachbearbeiter>Börti Fräli</lhd:sachbearbeiter>
    <lhd:telefon>02275/4525684</lhd:telefon>
    <lhd:email>[email protected]</lhd:email>
    <lhd:version>LHD-V5.5</lhd:version>
    <lhd:erstellt>2018-01-16</lhd:erstellt> 
    <lhd:finanzierungshaushalt>
        <lhd:ansatz_uab>770</lhd:ansatz_uab>
        <lhd:ansatz_ugl>000</lhd:ansatz_ugl>
        <lhd:konto>5880</lhd:konto>
        <lhd:konto_ugl>000</lhd:konto_ugl>
        <lhd:mvag_fhh>3126</lhd:mvag_fhh>
        <lhd:ord_aord>6</lhd:ord_aord>
        <lhd:sektor>0000</lhd:sektor>
        <lhd:ansatz_text>offizieller Ansatztext</lhd:ansatz_text>
        <lhd:konto_text>offizieller Kontotext</lhd:konto_text>
        <lhd:wert>9344974.61</lhd:wert>
    </lhd:finanzierungshaushalt> 
</lhd:kennsatz>  

这是我使用的VBA代码:

Public Sub CheckLHDModule()

  Dim docum
  Set docum = CreateObject("MSXML2.DOMDocument.6.0")
  Call docum.Load("C:\Temp\LHD-V55-Monat-Beispiel.xml")
  Dim dParseError
  Set dParseError = docum.validate()
  If dParseError.ErrorCode <> 0 Then
    Call MsgBox("Fehler " & dParseError.ErrorCode & ": '" & dParseError.Reason & "' bei XML-Validierung. ")
  End If

  Set dParseError = docum.validateNode(docum.ChildNodes.Item(1))
  If dParseError.ErrorCode <> 0 Then
    Call MsgBox("Fehler " & dParseError.ErrorCode & ": '" & dParseError.Reason & "' bei XML-Validierung. ")
  End If

End Sub

两个验证都返回错误:

  • 验证返回:

    该节点既无效也不无效,因为未找到DTD / Schema声明。(原文:“ Der Knoten ist wedergültignochungültig,Weil keine DTD / Schema-Deklaration gefunden wurde。”)

  • validatenode返回:

    已使用元素'{http://www.statistik.gv.at/LHD-V55/Schema} kennsatz',但未在DTD / Schema中声明。”(原始:“ Das Element'{http://www.statistik.gv.at/LHD-V55/Schema} kennsatz'wird verwendet,DTD / Schema nicht deklariert的语言。”]

在两种情况下,错误代码都是-1072898035。

但是http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd中定义了元素“ kennsatz”。这是文件的当前内容:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:lhd="http://www.statistik.gv.at/LHD-V55/Schema"
            xmlns:t="http://www.statistik.gv.at/LHD-V55/Typen"
            targetNamespace="http://www.statistik.gv.at/LHD-V55/Schema"
            elementFormDefault="qualified">

    <!-- Typdefinitionen importieren -->
    <xs:import  schemaLocation="LHD-V55_Typdefinitionen.xsd"
                namespace="http://www.statistik.gv.at/LHD-V55/Typen"/> 
    <!-- Elementdefinitionen inkludieren -->
    <xs:include     schemaLocation="LHD-V55_Elementdefinitionen.xsd"/>

    <xs:include schemaLocation="LHD-V55_finanzierungshaushalt.xsd"/>

    <!-- Kennsatz -->

    <xs:element name="kennsatz"> 
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="lhd:finanzjahr"/>

                <xs:element name="quartal">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="0"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element> 

                <xs:element name="monat">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:pattern value="[0][1-9]|[1][0-2]"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element> 
                <xs:element name="regkz" type="t:REGKZ"/>

                <xs:element name="periode">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:pattern value="m|M"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element> 

                <xs:element name="bundesland" type="t:BUNDESLAND"/>
                <xs:element name="verantwortlich" type="t:NAME"/> 
                <xs:element name="sachbearbeiter" type="t:NAME"/> 
                <xs:element ref="lhd:telefon"/>
                <xs:element ref="lhd:email"/> 
                <xs:element ref="lhd:version"/>
                <xs:element name="erstellt" type="xs:date"/>

                <!-- Kindelemente -->
                <xs:element ref="lhd:finanzierungshaushalt" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

当我使用notepad ++ XML-Tools插件验证“ LHD-V55-Monat-Beispiel.xml”时,验证成功。 (消息框:“ xml有效”)。因此文件本身似乎是正确的。

我想打个电话吗?为什么未正确验证XML文档?

xml vba xsd xsd-validation xml-validation
1个回答
0
投票

您使用的是xsi:schemaLocation,就好像它是xsi:noNamespaceSchemaLocation

代替

xsi:schemaLocation="http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd"

使用

xsi:schemaLocation="http://www.statistik.gv.at/LHD-V55/Schema
                    http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd"

即,使用空格分隔的[[pair of

xsi:schemaLocation="NAMESPACE_VALUE SCHEMA_LOCATION"
另请参阅How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
© www.soinside.com 2019 - 2024. All rights reserved.