Interface: Save Used XML Schema in Document

This commit is contained in:
PitzM 2024-06-10 09:48:43 +02:00
parent 1784f69041
commit a1609ee3c7

View File

@ -1,13 +1,8 @@
Imports System.Collections.Generic Imports System.IO
Imports System.IO
Imports System.Reflection.Emit
Imports System.Xml Imports System.Xml
Imports System.Xml.Serialization Imports System.Xml.Serialization
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports DigitalData.Modules.Interfaces.Exceptions Imports DigitalData.Modules.Interfaces.Exceptions
Imports DigitalData.Modules.Interfaces.ZUGFeRD Imports DigitalData.Modules.Interfaces.ZUGFeRD
Imports DigitalData.Modules.Interfaces.ZUGFeRDInterface
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports GdPicture14 Imports GdPicture14
@ -24,6 +19,11 @@ Public Class ZUGFeRDInterface
Public Const ZUGFERD_SPEC_10 = "ZUGFERD_10" Public Const ZUGFERD_SPEC_10 = "ZUGFERD_10"
Public Const ZUGFERD_SPEC_2x = "ZUGFERD_2x" Public Const ZUGFERD_SPEC_2x = "ZUGFERD_2x"
Public Const XMLSCHEMA_ZUGFERD_10 = "Version1_0"
Public Const XMLSCHEMA_ZUGFERD_20 = "Version2_0"
Public Const XMLSCHEMA_ZUGFERD_211 = "Version2_1_1"
Public Const XMLSCHEMA_ZUGFERD_22 = "Version2_2_FacturX"
Private ReadOnly ValidFilenames As New List(Of String) From { Private ReadOnly ValidFilenames As New List(Of String) From {
PDFEmbeds.ZUGFERD_XML_FILENAME.ToUpper, PDFEmbeds.ZUGFERD_XML_FILENAME.ToUpper,
PDFEmbeds.FACTUR_X_XML_FILENAME_DE.ToUpper, PDFEmbeds.FACTUR_X_XML_FILENAME_DE.ToUpper,
@ -57,6 +57,7 @@ Public Class ZUGFeRDInterface
Public Property XElementObject As XElement Public Property XElementObject As XElement
Public Property SchemaObject As Object Public Property SchemaObject As Object
Public Property Specification As String Public Property Specification As String
Public Property UsedXMLSchema As String
Public Property ValidationErrors As New List(Of ZugferdValidationError) Public Property ValidationErrors As New List(Of ZugferdValidationError)
End Class End Class
@ -279,6 +280,7 @@ Public Class ZUGFeRDInterface
Private Class AllowedType Private Class AllowedType
Public SchemaType As Type Public SchemaType As Type
Public Specification As String Public Specification As String
Public XMLSchema As String
End Class End Class
Public Function ValidateZUGFeRDDocument(pResult As ZugferdResult) As ZugferdResult Public Function ValidateZUGFeRDDocument(pResult As ZugferdResult) As ZugferdResult
@ -291,13 +293,15 @@ Public Class ZUGFeRDInterface
Dim oObject As Object = Nothing Dim oObject As Object = Nothing
Dim oSpecification As String = Nothing Dim oSpecification As String = Nothing
Dim oUsedXMLSchema As String = Nothing
Dim oAllowedTypes As New List(Of AllowedType) Dim oAllowedTypes As New List(Of AllowedType)
If _Options.AllowZugferd_1_0_Schema Then If _Options.AllowZugferd_1_0_Schema Then
oAllowedTypes.Add(New AllowedType With { oAllowedTypes.Add(New AllowedType With {
.SchemaType = GetType(Version1_0.CrossIndustryDocumentType), .SchemaType = GetType(Version1_0.CrossIndustryDocumentType),
.Specification = ZUGFERD_SPEC_10 .Specification = ZUGFERD_SPEC_10,
.XMLSchema = XMLSCHEMA_ZUGFERD_10
}) })
End If End If
@ -305,15 +309,18 @@ Public Class ZUGFeRDInterface
oAllowedTypes.AddRange(New List(Of AllowedType) From { oAllowedTypes.AddRange(New List(Of AllowedType) From {
New AllowedType With { New AllowedType With {
.SchemaType = GetType(Version2_0.CrossIndustryInvoiceType), .SchemaType = GetType(Version2_0.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x .Specification = ZUGFERD_SPEC_2x,
.XMLSchema = XMLSCHEMA_ZUGFERD_20
}, },
New AllowedType With { New AllowedType With {
.SchemaType = GetType(Version2_1_1.CrossIndustryInvoiceType), .SchemaType = GetType(Version2_1_1.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x .Specification = ZUGFERD_SPEC_2x,
.XMLSchema = XMLSCHEMA_ZUGFERD_211
}, },
New AllowedType With { New AllowedType With {
.SchemaType = GetType(Version2_2_FacturX.CrossIndustryInvoiceType), .SchemaType = GetType(Version2_2_FacturX.CrossIndustryInvoiceType),
.Specification = ZUGFERD_SPEC_2x .Specification = ZUGFERD_SPEC_2x,
.XMLSchema = XMLSCHEMA_ZUGFERD_22
} }
}) })
End If End If
@ -327,6 +334,7 @@ Public Class ZUGFeRDInterface
oReader = pResult.XElementObject.CreateReader() oReader = pResult.XElementObject.CreateReader()
oObject = oSerializer.Deserialize(oReader) oObject = oSerializer.Deserialize(oReader)
oSpecification = oType.Specification oSpecification = oType.Specification
oUsedXMLSchema = oType.XMLSchema
_logger.Debug("Serializing with type [{0}] succeeded", oTypeName) _logger.Debug("Serializing with type [{0}] succeeded", oTypeName)
Exit For Exit For
@ -345,6 +353,7 @@ Public Class ZUGFeRDInterface
End If End If
pResult.Specification = oSpecification pResult.Specification = oSpecification
pResult.UsedXMLSchema = oUsedXMLSchema
pResult.SchemaObject = oObject pResult.SchemaObject = oObject
Return pResult Return pResult