ну вот еще нашел...
| Код | XMLDoc.pas
//Change 1) ... FReadOnly: Boolean; FDoSpecialInsert: Boolean; // <-- add this (line 143 in my copy) FOnHostChildNotify: TNodeListNotification; FOnHostAttrNotify: TNodeListNotification; protected ...
//Change 2) ... function GetPrefix: DOMString; function GetReadOnly: Boolean; function GetSpecialInsert: Boolean; // <-- add this (line 168 in my copy) function GetText: DOMString; function GetXML: DOMString; procedure SetAttribute(const AttrName: DOMString; const Value: OleVariant); procedure SetChildValue(const IndexOrName: OleVariant; const Value: OleVariant); procedure SetNodeValue(const Value: OleVariant); procedure SetSpecialInsert(const DoSpecialInsert: Boolean); // <-- add this (line 174 in my copy) procedure SetReadOnly(const Value: Boolean); procedure SetText(const Value: DOMString); ....
//Change 3) ... property OwnerDocument: TXMLDocument read FDocument; property ParentNode: TXMLNode read FParentNode; property SpecialInsert: Boolean read GetSpecialInsert write SetSpecialInsert; // <-- add this (line 247 for me) public constructor Create(const ADOMNode: IDOMNode; const AParentNode: TXMLNode; ...
//Change 4) ... constructor TXMLNode.Create(const ADOMNode: IDOMNode; const AParentNode: TXMLNode; const OwnerDoc: TXMLDocument); begin inherited Create; ... FIsDocElement := Assigned(FParentNode) and (FParentNode.GetNodeType = ntDocument) and (GetNodeType = ntElement); FDoSpecialInsert := False; // <-- add this line end;
//Change 5)
procedure TXMLNode.ChildListNotify(Operation: TNodeListOperation; var Node: IXMLNode; const IndexOrName: OleVariant; BeforeOperation: Boolean); const NodeChangeMap: array[TNodeListOperation] of TNodeChange = (ncInsertChild, ncRemoveChild, ncInsertChild); var I, CNUpdateCount: Integer; // <-- add CNUpdateCount variable HostedNode: TXMLNode; begin DoNodeChange(NodeChangeMap[Operation], BeforeOperation); CNUpdateCount := ChildNodes.UpdateCount; // <-- add this line if BeforeOperation and (CNUpdateCount = 0) then begin // <-- modify this line case Operation of nlRemove: ... nlInsert: ... nlCreateNode: ... end; // DATE: 2.5.2005 - MAJOR HACK - // Observation: The IXML* stuff is a wrapper around the IDOM* stuff - and two // separate sets of nodes are maintained in a synchronised state (?!!!) - in 'List' // for the IXML* stuff, and a DOMNode for the IDOM* stuff. If BeginUpdate/EndUpdate // used, the IDOM stuff doesn't get updated, but the IXML* stuff does - nodes are // created/removed, but only in List (?!!!). Without BeginUpdate/EndUpdate, writes // are VERY slow (still slow anyway, but more than 2x as quick). The slow part seems // to be due to: // Assert(DOMNode.childNodes.length = FChildNodes.Count); // if LongWord(IndexOrName) >= LongWord(DOMNode.ChildNodes.length) then // ...those two bits. So I've added a new chunk (below) which misses out those tests // - they're designed for a generic set of circumstances, whereas I can KNOW that // I'm just adding new nodes when I set the new SpecialInsert switch, so the tests // can be missed out (?!!!). end else if (SpecialInsert) and (BeforeOperation) and (CNUpdateCount > 0) then begin // <-- add DOMNode.appendChild(Node.DOMNode); // <-- add (Node as IXMLNodeAccess).SetParentNode(Self); // <--- add end; if Assigned(FHostedNodes) then for I := 0 to FHostedNodes.Count - 1 do begin HostedNode := TXMLNode(FHostedNodes[I]); if Assigned(HostedNode.OnHostChildNotify) then HostedNode.OnHostChildNotify(Operation, Node, IndexOrName, BeforeOperation); end; end;
//Change 6)
// Add these somewhere within the TXMLNode listing function TXMLNode.GetSpecialInsert: Boolean; begin Result := FDoSpecialInsert; end;
procedure TXMLNode.SetSpecialInsert(const DoSpecialInsert: Boolean); begin FDoSpecialInsert := DoSpecialInsert; end; { I'm copying those bits by doing a dff comparison between the original and modified copies, so there's a chance I might've missed something out. To use the 'faster' Insert you have to set the 'SpecialInsert' property to True, then False when you're finished. Example: } // Add some strings to an XML document: MyXMLDoc is a global TXMLDocument descendant procedure TFileListHTTPHead.AddToXML(const AStringList: TStringList); var Loop: Integer; begin MyXMLDoc.ANode.ChildNodes.BeginUpdate; try MyXMLDoc.ANode.SpecialInsert := True; for Loop := 0 to AStringList.Count - 1 do MyXMLDoc.ANode.Add(AStringList.Strings[Loop]); finally MyXMLDoc.ANode.EndUpdate; MyXMLDoc.ANode.SpecialInsert := False; end; end;
|
Добавлено @ 13:44
| Код | //create root node Root := XMLDocument2.Node.AddChild('Pizza');
ChildLevel1 := Root.AddChild('Toppings'); ChildLevel2 := ChildLevel1.AddChild('ToppingsA'); ChildLevel2.Text := cheddar; ChildLevel2 := ChildLevel1.AddChild('ToppingsB'); ChildLevel2.Text := pepparoni; ChildLevel2 := ChildLevel1.AddChild('ToppingsC'); ChildLevel2.Text := cheese; ChildLevel2 := ChildLevel1.AddChild('ToppingsD'); ChildLevel2.Text := bbqsauce; ChildLevel2 := ChildLevel1.AddChild('ToppingsE'); ChildLevel2.Text := onions;
XMLDocument2.SaveToFile(GetCurrentDir + '\filename.xml');
|
| Код | var root, node: iXMLNode; i: word;
begin root := XMLDocument.AddChild( "table" );
table.First; while not table.eof do begin
node := root.AddChild( "record" );
for i := 0 to table.FieldCount -1 do node.AddChild( table.Fields[ i ].FieldName ).NodeValue := table.Fields[ i ].AsString;
table.Next;
end; //not eof
end;
|
|