From 96eeb95d17203acf06dbfabeabcc9af33dadece4 Mon Sep 17 00:00:00 2001
From: Philipp Winkel
Date: Tue, 3 Nov 2020 17:11:34 +0100
Subject: [PATCH] XML Validation: CreateRequiredElements with correct
namespaces
---
Units/DelphiXMLDataBindingGenerator.pas | 12 +++++++++---
Units/DelphiXMLDataBindingResources.pas | 2 +-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/Units/DelphiXMLDataBindingGenerator.pas b/Units/DelphiXMLDataBindingGenerator.pas
index d8ff615..2027b33 100644
--- a/Units/DelphiXMLDataBindingGenerator.pas
+++ b/Units/DelphiXMLDataBindingGenerator.pas
@@ -1579,7 +1579,9 @@ var
elementSortCount: Integer;
elementSortOrder: string;
elementRequired: string;
+ elementNamespaceRequired: string;
elementRequiredCount: Integer;
+ elementNamespaceRequiredCount: Integer;
attributeRequired: string;
attributeRequiredCount: Integer;
@@ -1610,8 +1612,10 @@ begin
begin
case propertyItem.PropertyType of
ptSimple:
- AddArrayElement(elementRequired, elementRequiredCount, QuotedStr(propertyItem.Name));
-
+ begin
+ AddArrayElement(elementRequired, elementRequiredCount, QuotedStr(propertyItem.Name));
+ AddArrayElement(elementNamespaceRequired, elementNamespaceRequiredCount, QuotedStr(propertyItem.TargetNamespace));
+ end;
ptItem:
{ For Item properties, we call our getter property. This ensures the child element exists,
but also that it is created using our binding implementation. Otherwise there will be no
@@ -1627,8 +1631,10 @@ begin
if elementRequiredCount > 0 then
begin
Delete(elementRequired, 1, 2);
+ Delete(elementNamespaceRequired, 1, 2);
AWriter.WriteLineNamedFmt(IfThen(AStrict, XSDValidateStrictMethodImplementationRequired, XSDValidateMethodImplementationRequired),
- ['RequiredElements', elementRequired]);
+ ['RequiredElements', elementRequired,
+ 'RequiredElementNamespaces', elementNamespaceRequired]);
end;
diff --git a/Units/DelphiXMLDataBindingResources.pas b/Units/DelphiXMLDataBindingResources.pas
index 12fbda1..e6ea2a8 100644
--- a/Units/DelphiXMLDataBindingResources.pas
+++ b/Units/DelphiXMLDataBindingResources.pas
@@ -114,7 +114,7 @@ const
XSDValidateMethodImplementationBegin = 'procedure TXML%:s.XSDValidate;' + CrLf +
'begin';
- XSDValidateMethodImplementationRequired = ' CreateRequiredElements(Self, [%:s]);';
+ XSDValidateMethodImplementationRequired = ' CreateRequiredElements(Self, [%:s], [%:s]);';
XSDValidateMethodImplementationComplex = ' Get%:s;';
XSDValidateMethodImplementationAttrib = ' CreateRequiredAttributes(Self, [%:s]);';
XSDValidateMethodImplementationSort = ' SortChildNodes(Self, [%:s]);';