Support for namespaces in child nodes
This commit is contained in:
parent
be56cf001a
commit
cc62e18e4e
@ -11,6 +11,8 @@ interface
|
||||
uses
|
||||
Classes,
|
||||
SysUtils,
|
||||
XMLDoc,
|
||||
xmldom,
|
||||
XMLIntf;
|
||||
|
||||
|
||||
@ -28,6 +30,22 @@ type
|
||||
end;
|
||||
|
||||
|
||||
TX2XMLNode = class(TXMLNode)
|
||||
private
|
||||
function GetChildNodesNS(const ANodeName, ANamespaceURI: DOMString): IXMLNode;
|
||||
protected
|
||||
property ChildNodesNS[const ANodeName, ANamespaceURI: DOMString]: IXMLNode read GetChildNodesNS;
|
||||
end;
|
||||
|
||||
|
||||
TX2XMLNodeCollection = class(TXMLNodeCollection)
|
||||
private
|
||||
function GetChildNodesNS(const ANodeName, ANamespaceURI: DOMString): IXMLNode;
|
||||
protected
|
||||
property ChildNodesNS[const ANodeName, ANamespaceURI: DOMString]: IXMLNode read GetChildNodesNS;
|
||||
end;
|
||||
|
||||
|
||||
const
|
||||
AllTimeFragments = [Low(TXMLTimeFragment)..High(TXMLTimeFragment)];
|
||||
|
||||
@ -122,6 +140,26 @@ type
|
||||
|
||||
|
||||
|
||||
{ TX2XMLNode }
|
||||
function TX2XMLNode.GetChildNodesNS(const ANodeName, ANamespaceURI: DOMString): IXMLNode;
|
||||
begin
|
||||
Result := ChildNodes.FindNode(ANodeName, ANamespaceURI);
|
||||
if (not Assigned(Result)) and (doNodeAutoCreate in OwnerDocument.Options) then
|
||||
Result := AddChild(ANodeName, ANamespaceURI);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ TX2XMLNodeCollection }
|
||||
function TX2XMLNodeCollection.GetChildNodesNS(const ANodeName, ANamespaceURI: DOMString): IXMLNode;
|
||||
begin
|
||||
Result := ChildNodes.FindNode(ANodeName, ANamespaceURI);
|
||||
if (not Assigned(Result)) and (doNodeAutoCreate in OwnerDocument.Options) then
|
||||
Result := AddChild(ANodeName, ANamespaceURI);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
function DateTimeToXML(ADate: TDateTime; AFormat: TXMLDateTimeFormat; ATimeFragments: TXMLTimeFragments): string;
|
||||
var
|
||||
formatSettings: TFormatSettings;
|
||||
|
@ -1334,7 +1334,7 @@ begin
|
||||
sourceCode.Add('begin');
|
||||
|
||||
if AProperty.HasTargetNamespace then
|
||||
sourceCode.Add(' Result := (ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'') as IXML%<PropertyItemName>:s);')
|
||||
sourceCode.Add(' Result := (ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''] as IXML%<PropertyItemName>:s);')
|
||||
else
|
||||
sourceCode.Add(' Result := (ChildNodes[''%<PropertySourceName>:s''] as IXML%<PropertyItemName>:s);');
|
||||
|
||||
|
@ -151,7 +151,7 @@ const
|
||||
{ dntElementNS }
|
||||
'function TXML%<Name>:s.Get%<PropertyName>:sIsNil: Boolean;' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' Result := GetNodeIsNil(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s''));' + CrLf +
|
||||
' Result := GetNodeIsNil(ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s'']);' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
@ -168,7 +168,7 @@ const
|
||||
{ dntElementNS }
|
||||
'procedure TXML%<Name>:s.Set%<PropertyName>:sIsNil(const Value: Boolean);' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' SetNodeIsNil(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s''), Value);' + CrLf +
|
||||
' SetNodeIsNil(ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''], Value);' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
@ -185,14 +185,14 @@ const
|
||||
{ dntElement }
|
||||
'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' Result := ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').Text;' + CrLf +
|
||||
' Result := ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''].Text;' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
|
||||
PropertyImplMethodGetTextAttr = 'function TXML%<Name>:s.Get%<PropertyName>:sText: WideString;' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' Result := AttributeNodes[''%<PropertySourceName>:s''].Text;' + CrLf +
|
||||
' Result := AttributeNodes[''%<PropertySourceName>:s''].Text;' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf;
|
||||
|
||||
@ -208,7 +208,7 @@ const
|
||||
{ dntElementNS }
|
||||
'procedure TXML%<Name>:s.Set%<PropertyName>:sText(const Value: WideString);' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').NodeValue := Value;' + CrLf +
|
||||
' ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''].NodeValue := Value;' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
@ -231,7 +231,7 @@ const
|
||||
{ dntElementNS }
|
||||
'procedure TXML%<Name>:s.Save%<PropertyName>:sToStream(AStream: TStream);' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' Base64DecodeToStream(Trim(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').Text), AStream);' + CrLf +
|
||||
' Base64DecodeToStream(Trim(ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''].Text), AStream);' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
@ -248,7 +248,7 @@ const
|
||||
{ dntElementNS }
|
||||
'procedure TXML%<Name>:s.Save%<PropertyName>:sToFile(const AFileName: string);' + CrLf +
|
||||
'begin' + CrLf +
|
||||
' Base64DecodeToFile(Trim(ChildNodes.FindNode(''%<PropertySourceName>:s'', ''%<Namespace>:s'').Text), AFileName);' + CrLf +
|
||||
' Base64DecodeToFile(Trim(ChildNodesNS[''%<PropertySourceName>:s'', ''%<Namespace>:s''].Text), AFileName);' + CrLf +
|
||||
'end;' + CrLf +
|
||||
'' + CrLf
|
||||
);
|
||||
@ -275,10 +275,10 @@ const
|
||||
|
||||
|
||||
CollectionInterface = 'IXMLNodeCollection';
|
||||
CollectionClass = 'TXMLNodeCollection';
|
||||
CollectionClass = 'TX2XMLNodeCollection';
|
||||
|
||||
ItemInterface = 'IXMLNode';
|
||||
ItemClass = 'TXMLNode';
|
||||
ItemClass = 'TX2XMLNode';
|
||||
|
||||
|
||||
|
||||
@ -369,7 +369,7 @@ const
|
||||
{ daGet }
|
||||
(
|
||||
{ dntElement } ' %<Destination>:s := ChildNodes[''%<Source>:s''].NodeValue;',
|
||||
{ dntElementNS } ' %<Destination>:s := ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue;',
|
||||
{ dntElementNS } ' %<Destination>:s := ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].NodeValue;',
|
||||
{ dntAttribute } ' %<Destination>:s := AttributeNodes[''%<Source>:s''].NodeValue;',
|
||||
{ dntNodeValue } ' %<Destination>:s := GetNodeValue;',
|
||||
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
||||
@ -377,7 +377,7 @@ const
|
||||
{ daSet }
|
||||
(
|
||||
{ dntElement } ' ChildNodes[''%<Destination>:s''].NodeValue := %<Source>:s;',
|
||||
{ dntElementNS } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := %<Source>:s;',
|
||||
{ dntElementNS } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := %<Source>:s;',
|
||||
{ dntAttribute } ' SetAttribute(''%<Destination>:s'', %<Source>:s);',
|
||||
{ dntNodeValue } ' SetNodeValue(%<Source>:s);',
|
||||
{ dntCustom } ' %<Destination>:s := %<Source>:s;'
|
||||
@ -405,13 +405,13 @@ const
|
||||
(
|
||||
{ tcNone } '',
|
||||
{ tcBoolean } '',
|
||||
{ tcFloat } ' %<Destination>:s := XMLToFloat(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue);',
|
||||
{ tcDateTime } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtDateTime);',
|
||||
{ tcDate } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtDate);',
|
||||
{ tcTime } ' %<Destination>:s := XMLToDateTime(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').NodeValue, xdtTime);',
|
||||
{ tcString } ' %<Destination>:s := ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').Text;',
|
||||
{ tcBase64 } ' %<Destination>:s := Base64Decode(Trim(ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'').Text));',
|
||||
{ tcNode } ' %<Destination>:s := ChildNodes.FindNode(''%<Source>:s'', ''%<Namespace>:s'');'
|
||||
{ tcFloat } ' %<Destination>:s := XMLToFloat(ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].NodeValue);',
|
||||
{ tcDateTime } ' %<Destination>:s := XMLToDateTime(ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].NodeValue, xdtDateTime);',
|
||||
{ tcDate } ' %<Destination>:s := XMLToDateTime(ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].NodeValue, xdtDate);',
|
||||
{ tcTime } ' %<Destination>:s := XMLToDateTime(ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].NodeValue, xdtTime);',
|
||||
{ tcString } ' %<Destination>:s := ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].Text;',
|
||||
{ tcBase64 } ' %<Destination>:s := Base64Decode(Trim(ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''].Text));',
|
||||
{ tcNode } ' %<Destination>:s := ChildNodesNS[''%<Source>:s'', ''%<Namespace>:s''];'
|
||||
),
|
||||
{ dntAttribute }
|
||||
(
|
||||
@ -467,14 +467,14 @@ const
|
||||
{ dntElementNS }
|
||||
(
|
||||
{ tcNone } '',
|
||||
{ tcBoolean } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := BoolToXML(%<Source>:s);',
|
||||
{ tcFloat } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := FloatToXML(%<Source>:s);',
|
||||
{ tcDateTime } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtDateTime);',
|
||||
{ tcDate } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtDate);',
|
||||
{ tcTime } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := DateTimeToXML(%<Source>:s, xdtTime);',
|
||||
{ tcBoolean } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := BoolToXML(%<Source>:s);',
|
||||
{ tcFloat } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := FloatToXML(%<Source>:s);',
|
||||
{ tcDateTime } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := DateTimeToXML(%<Source>:s, xdtDateTime);',
|
||||
{ tcDate } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := DateTimeToXML(%<Source>:s, xdtDate);',
|
||||
{ tcTime } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := DateTimeToXML(%<Source>:s, xdtTime);',
|
||||
{ tcString } '',
|
||||
{ tcBase64 } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'').NodeValue := Base64Encode(%<Source>:s);',
|
||||
{ tcNode } ' ChildNodes.FindNode(''%<Destination>:s'', ''%<Namespace>:s'') := %<Source>:s;'
|
||||
{ tcBase64 } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''].NodeValue := Base64Encode(%<Source>:s);',
|
||||
{ tcNode } ' ChildNodesNS[''%<Destination>:s'', ''%<Namespace>:s''] := %<Source>:s;'
|
||||
),
|
||||
{ dntAttribute }
|
||||
(
|
||||
|
@ -976,6 +976,7 @@ var
|
||||
propertyType: TXMLDataBindingItem;
|
||||
propertyItem: TXMLDataBindingProperty;
|
||||
namespace: string;
|
||||
schemaDef: IXMLSchemaDef;
|
||||
|
||||
begin
|
||||
propertyType := ProcessElement(ASchema, AElement);
|
||||
@ -991,9 +992,14 @@ begin
|
||||
AElement.Name,
|
||||
AElement.DataType);
|
||||
|
||||
if not VarIsNull(AElement.SchemaDef.TargetNamespace) then
|
||||
if Assigned(AElement.Ref) then
|
||||
schemaDef := AElement.Ref.SchemaDef
|
||||
else
|
||||
schemaDef := AElement.SchemaDef;
|
||||
|
||||
if Assigned(schemaDef) and (not VarIsNull(schemaDef.TargetNamespace)) then
|
||||
begin
|
||||
namespace := AElement.SchemaDef.TargetNamespace;
|
||||
namespace := schemaDef.TargetNamespace;
|
||||
if namespace <> Schemas[0].TargetNamespace then
|
||||
propertyItem.TargetNamespace := namespace;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user