This is a sample XML which I got from here: 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>boerti.fraenzli@steiermark.gv.at</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>
This is the VBA-code I use:
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
Both validations return an error:
Validate returns:
The node is neither valid nor invalid because no DTD/Schema declaration was found.
(Original: "Der Knoten ist weder gültig noch ungültig, weil keine DTD/Schema-Deklaration gefunden wurde.")validatenode returns:
The element '{http://www.statistik.gv.at/LHD-V55/Schema}kennsatz' is used but not declared in the DTD/Schema."
(Original: "Das Element '{http://www.statistik.gv.at/LHD-V55/Schema}kennsatz' wird verwendet, aber es ist im DTD/Schema nicht deklariert .")
The error code is -1072898035 in both cases.
But in http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd there is the element "kennsatz" defined. This is the current content of the file:
<?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>
When I validate "LHD-V55-Monat-Beispiel.xml" with notepad++ XML-Tools addon, the validation is successful. (MessageBox: "The xml is valid" ). So the file itself seems to be correct.
Do I miss a call? Why is the XML-Document not validated correctly?
Edits:
I tried to use:
xsi:schemaLocation="http://www.statistik.gv.at/LHD-V55/Schema http://www.statistik.at/GBS-Schema/LHD/LHD-V55_kennsatz-monat.xsd"
but it did not change anything.
Reduced example:
I changed the content of the xml to:
<?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.gv.at/LHD-V55/Schema file:///C:/RadLokal/trunk/Test/Access/MiniSchema.xsd">
<lhd:finanzjahr>gogo</lhd:finanzjahr>
</lhd:kennsatz>
And the content of the file: C:\RadLokal\trunk\Test\Access\MiniSchema.xsd is:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lhd="http://www.statistik.gv.at/LHD-V55/Schema"
targetNamespace="http://www.statistik.gv.at/LHD-V55/Schema"
elementFormDefault="qualified">
<xs:element name="kennsatz">
<xs:complexType>
<xs:sequence>
<xs:element name="finanzjahr" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The error is the same as before.