1
0
mirror of synced 2024-11-23 06:03:50 +00:00

Fixed relative schemas references in relative schema references (yo dawg...)

Fixed ItemNS for collection items where the parent node is in another namespace
This commit is contained in:
Mark van Renswoude 2017-02-17 15:27:30 +01:00
parent fe7f2eb952
commit 79d87acb61
3 changed files with 69 additions and 37 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
Units/__history/
*.local
*.identcache
bin/
lib/

View File

@ -876,6 +876,13 @@ begin
if hasPrototype and (ASection = dxsImplementation) then
begin
AWriter.WriteLine(' inherited;');
if AItem.IsCollection and (AItem.TargetNamespace <> AItem.CollectionItem.TargetNamespace) then
begin
AWriter.WriteLine;
AWriter.WriteLine(' ItemNS := ''%s'';', [AItem.CollectionItem.TargetNamespace]);
end;
AWriter.WriteLine('end;');
AWriter.WriteLine;
end;

View File

@ -51,7 +51,7 @@ type
function GetSchemaCount: Integer;
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
protected
function LoadSchema(const AStream: TStream; const ASchemaName: String): TXMLDataBindingSchema;
function LoadSchema(const AStream: TStream; const ASchemaName, ASourceFileName: String): TXMLDataBindingSchema;
function GetSchemaData(const ALocation: String; out ASourceFileName: String): TStream;
function FindSchema(const ALocation: String): TXMLDataBindingSchema;
@ -408,13 +408,10 @@ end;
procedure TXMLDataBindingGenerator.Execute(const AStream: TStream; const ASchemaName: String);
var
schemaIndex: Integer;
schema: TXMLDataBindingSchema;
begin
FSchemas.Clear;
schema := LoadSchema(AStream, ASchemaName);
if Assigned(schema) then
schema.SourceFileName := SourceFileName;
LoadSchema(AStream, ASchemaName, SourceFileName);
if SchemaCount > 0 then
begin
@ -474,7 +471,7 @@ end;
function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASchemaName: String): TXMLDataBindingSchema;
function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASchemaName, ASourceFileName: String): TXMLDataBindingSchema;
procedure HandleDocRefs(const ADocRefs: IXMLSchemaDocRefs; ASchema: TXMLDataBindingSchema);
var
@ -498,22 +495,26 @@ function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASche
if Assigned(refStream) then
try
refSchema := LoadSchema(refStream, schemaName);
if Assigned(refSchema) then
refSchema.SourceFileName := sourceFileName;
refSchema := LoadSchema(refStream, schemaName, sourceFileName);
finally
FreeAndNil(refStream);
end;
end;
if Assigned(refSchema) then
begin
// Update the schema location to an absolute path,
// the Delphi XMLSchema unit has trouble resolving relative references
// in a relatively referenced file.
ADocRefs[refIndex].SchemaLocation := refSchema.SourceFileName;
ASchema.AddInclude(refSchema);
end;
end;
end;
var
currentDir: string;
schemaDoc: IXMLSchemaDoc;
schemaDef: IXMLSchemaDef;
@ -525,11 +526,18 @@ begin
Result := TXMLDataBindingSchema.Create(Self);
Result.SchemaDef := schemaDef;
Result.SchemaName := ASchemaName;
Result.SourceFileName := ExpandFileName(ASourceFileName);
FSchemas.Add(Result);
currentDir := GetCurrentDir;
SetCurrentDir(ExtractFilePath(Result.SourceFileName));
try
{ Handle imports / includes }
HandleDocRefs(schemaDef.SchemaImports, Result);
HandleDocRefs(schemaDef.SchemaIncludes, Result);
finally
SetCurrentDir(currentDir);
end;
end;
@ -549,7 +557,7 @@ begin
if FileExists(includePath + ALocation) then
begin
ASourceFileName := includePath + ALocation;
ASourceFileName := ExpandFileName(includePath + ALocation);
Result := TFileStream.Create(ASourceFileName, fmOpenRead or fmShareDenyNone);
break;
end;
@ -581,17 +589,23 @@ begin
if ASchema.ItemsGenerated then
exit;
OutputDebugString(PChar('> ' + ASchema.SchemaName));
ASchema.ItemsGenerated := True;
OutputDebugString('Includes...');
{ First generate the objects for all includes and imports, so we can get
proper references. }
for includeIndex := 0 to Pred(ASchema.IncludeCount) do
GenerateSchemaObjects(ASchema.Includes[includeIndex], False);
OutputDebugString(PChar(ASchema.SchemaName + ': Generate objects'));
GenerateElementObjects(ASchema, ARootDocument);
GenerateComplexTypeObjects(ASchema);
GenerateSimpleTypeObjects(ASchema);
GenerateAttributeObjects(ASchema);
OutputDebugString(PChar('< ' + ASchema.SchemaName));
end;
@ -676,7 +690,8 @@ begin
end else if simpleType.DerivationMethod = sdmRestriction then
begin
baseType := simpleType.BaseType;
if Assigned(baseType) then
begin
while Assigned(baseType.BaseType) do
baseType := baseType.BaseType;
@ -693,6 +708,10 @@ begin
simpleTypeAlias.TargetNamespace := namespace;
ASchema.AddItem(simpleTypeAlias);
end;
end else
begin
// ...I literally can't even.
end;
end;
end;
end;
@ -1126,6 +1145,7 @@ begin
// #ToDo1 -oMvR: set type "union"
ASchema.AddItem(simpleAliasItem);
break;
end
else
typeDef := nil;