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:
parent
fe7f2eb952
commit
79d87acb61
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Units/__history/
|
||||||
|
*.local
|
||||||
|
*.identcache
|
||||||
|
bin/
|
||||||
|
lib/
|
@ -876,6 +876,13 @@ begin
|
|||||||
if hasPrototype and (ASection = dxsImplementation) then
|
if hasPrototype and (ASection = dxsImplementation) then
|
||||||
begin
|
begin
|
||||||
AWriter.WriteLine(' inherited;');
|
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;');
|
||||||
AWriter.WriteLine;
|
AWriter.WriteLine;
|
||||||
end;
|
end;
|
||||||
|
@ -51,7 +51,7 @@ type
|
|||||||
function GetSchemaCount: Integer;
|
function GetSchemaCount: Integer;
|
||||||
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
function GetSchemas(Index: Integer): TXMLDataBindingSchema;
|
||||||
protected
|
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 GetSchemaData(const ALocation: String; out ASourceFileName: String): TStream;
|
||||||
function FindSchema(const ALocation: String): TXMLDataBindingSchema;
|
function FindSchema(const ALocation: String): TXMLDataBindingSchema;
|
||||||
|
|
||||||
@ -408,13 +408,10 @@ end;
|
|||||||
procedure TXMLDataBindingGenerator.Execute(const AStream: TStream; const ASchemaName: String);
|
procedure TXMLDataBindingGenerator.Execute(const AStream: TStream; const ASchemaName: String);
|
||||||
var
|
var
|
||||||
schemaIndex: Integer;
|
schemaIndex: Integer;
|
||||||
schema: TXMLDataBindingSchema;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
FSchemas.Clear;
|
FSchemas.Clear;
|
||||||
schema := LoadSchema(AStream, ASchemaName);
|
LoadSchema(AStream, ASchemaName, SourceFileName);
|
||||||
if Assigned(schema) then
|
|
||||||
schema.SourceFileName := SourceFileName;
|
|
||||||
|
|
||||||
if SchemaCount > 0 then
|
if SchemaCount > 0 then
|
||||||
begin
|
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);
|
procedure HandleDocRefs(const ADocRefs: IXMLSchemaDocRefs; ASchema: TXMLDataBindingSchema);
|
||||||
var
|
var
|
||||||
@ -498,22 +495,26 @@ function TXMLDataBindingGenerator.LoadSchema(const AStream: TStream; const ASche
|
|||||||
|
|
||||||
if Assigned(refStream) then
|
if Assigned(refStream) then
|
||||||
try
|
try
|
||||||
refSchema := LoadSchema(refStream, schemaName);
|
refSchema := LoadSchema(refStream, schemaName, sourceFileName);
|
||||||
|
|
||||||
if Assigned(refSchema) then
|
|
||||||
refSchema.SourceFileName := sourceFileName;
|
|
||||||
finally
|
finally
|
||||||
FreeAndNil(refStream);
|
FreeAndNil(refStream);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Assigned(refSchema) then
|
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);
|
ASchema.AddInclude(refSchema);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
|
currentDir: string;
|
||||||
schemaDoc: IXMLSchemaDoc;
|
schemaDoc: IXMLSchemaDoc;
|
||||||
schemaDef: IXMLSchemaDef;
|
schemaDef: IXMLSchemaDef;
|
||||||
|
|
||||||
@ -525,11 +526,18 @@ begin
|
|||||||
Result := TXMLDataBindingSchema.Create(Self);
|
Result := TXMLDataBindingSchema.Create(Self);
|
||||||
Result.SchemaDef := schemaDef;
|
Result.SchemaDef := schemaDef;
|
||||||
Result.SchemaName := ASchemaName;
|
Result.SchemaName := ASchemaName;
|
||||||
|
Result.SourceFileName := ExpandFileName(ASourceFileName);
|
||||||
FSchemas.Add(Result);
|
FSchemas.Add(Result);
|
||||||
|
|
||||||
|
currentDir := GetCurrentDir;
|
||||||
|
SetCurrentDir(ExtractFilePath(Result.SourceFileName));
|
||||||
|
try
|
||||||
{ Handle imports / includes }
|
{ Handle imports / includes }
|
||||||
HandleDocRefs(schemaDef.SchemaImports, Result);
|
HandleDocRefs(schemaDef.SchemaImports, Result);
|
||||||
HandleDocRefs(schemaDef.SchemaIncludes, Result);
|
HandleDocRefs(schemaDef.SchemaIncludes, Result);
|
||||||
|
finally
|
||||||
|
SetCurrentDir(currentDir);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -549,7 +557,7 @@ begin
|
|||||||
|
|
||||||
if FileExists(includePath + ALocation) then
|
if FileExists(includePath + ALocation) then
|
||||||
begin
|
begin
|
||||||
ASourceFileName := includePath + ALocation;
|
ASourceFileName := ExpandFileName(includePath + ALocation);
|
||||||
Result := TFileStream.Create(ASourceFileName, fmOpenRead or fmShareDenyNone);
|
Result := TFileStream.Create(ASourceFileName, fmOpenRead or fmShareDenyNone);
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
@ -581,17 +589,23 @@ begin
|
|||||||
if ASchema.ItemsGenerated then
|
if ASchema.ItemsGenerated then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
OutputDebugString(PChar('> ' + ASchema.SchemaName));
|
||||||
ASchema.ItemsGenerated := True;
|
ASchema.ItemsGenerated := True;
|
||||||
|
|
||||||
|
OutputDebugString('Includes...');
|
||||||
{ First generate the objects for all includes and imports, so we can get
|
{ First generate the objects for all includes and imports, so we can get
|
||||||
proper references. }
|
proper references. }
|
||||||
for includeIndex := 0 to Pred(ASchema.IncludeCount) do
|
for includeIndex := 0 to Pred(ASchema.IncludeCount) do
|
||||||
GenerateSchemaObjects(ASchema.Includes[includeIndex], False);
|
GenerateSchemaObjects(ASchema.Includes[includeIndex], False);
|
||||||
|
|
||||||
|
OutputDebugString(PChar(ASchema.SchemaName + ': Generate objects'));
|
||||||
|
|
||||||
GenerateElementObjects(ASchema, ARootDocument);
|
GenerateElementObjects(ASchema, ARootDocument);
|
||||||
GenerateComplexTypeObjects(ASchema);
|
GenerateComplexTypeObjects(ASchema);
|
||||||
GenerateSimpleTypeObjects(ASchema);
|
GenerateSimpleTypeObjects(ASchema);
|
||||||
GenerateAttributeObjects(ASchema);
|
GenerateAttributeObjects(ASchema);
|
||||||
|
|
||||||
|
OutputDebugString(PChar('< ' + ASchema.SchemaName));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -676,7 +690,8 @@ begin
|
|||||||
end else if simpleType.DerivationMethod = sdmRestriction then
|
end else if simpleType.DerivationMethod = sdmRestriction then
|
||||||
begin
|
begin
|
||||||
baseType := simpleType.BaseType;
|
baseType := simpleType.BaseType;
|
||||||
|
if Assigned(baseType) then
|
||||||
|
begin
|
||||||
while Assigned(baseType.BaseType) do
|
while Assigned(baseType.BaseType) do
|
||||||
baseType := baseType.BaseType;
|
baseType := baseType.BaseType;
|
||||||
|
|
||||||
@ -693,6 +708,10 @@ begin
|
|||||||
simpleTypeAlias.TargetNamespace := namespace;
|
simpleTypeAlias.TargetNamespace := namespace;
|
||||||
ASchema.AddItem(simpleTypeAlias);
|
ASchema.AddItem(simpleTypeAlias);
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
// ...I literally can't even.
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1126,6 +1145,7 @@ begin
|
|||||||
// #ToDo1 -oMvR: set type "union"
|
// #ToDo1 -oMvR: set type "union"
|
||||||
|
|
||||||
ASchema.AddItem(simpleAliasItem);
|
ASchema.AddItem(simpleAliasItem);
|
||||||
|
break;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
typeDef := nil;
|
typeDef := nil;
|
||||||
|
Loading…
Reference in New Issue
Block a user