• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

XML - Add/Edit/Delete/List

hi, what is the most easest way of doing Add/Edit/Delete/List with XML?

could you please provide code.

Sal.
0
SaLz
Asked:
SaLz
  • 6
  • 6
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:
Sal,

This is a really basic example, but should you give you some ideas of how this is handled. If you have a specific example (xml) that you would like demonstrated then let me know.Same with any questions that you might have.

Regards,
Russell

---

unit Unit1;

interface

////////////////////////////////////////////////////////////////////////////////
//   To use this example, you must import the msxml library. I used version 2
//   (msxml2.dll) which is pretty common, but the same techniques apply to all
//   versions:
//
//   Project | Import Type Library | Add | Select "c:\%windows%\system32\msxml%number%.dll"
//   where %windows% is your windows directory, and %number% is the XML version to import.
//   Once imported, add the unit name (eg MSXML2_TLB) to your include list
//
//
////////////////////////////////////////////////////////////////////////////////
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  MSXML2_TLB, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var  objDoc:        IXMLDOMDocument2;
     objNode:       IXMLDOMNode;
begin

  // Create document object
  objDoc:=CoDOMDocument.Create;

  // You can load a document by performing
  // objDoc.load(filename); - from file
  // objDoc.loadXlm(string); - from string

  // Create an element
  objNode:=objDoc.createElement('Testing1');

  // Set some text for the element
  objNode.text:='Hello world';

  // Add this to the document
  objDoc.appendChild(objNode);

  // Get textual version of xml
  ShowMessage(objDoc.xml);

  // Add a child node
  objNode:=objDoc.createElement('Testing2');

  // Set some text for the element
  objNode.text:='Hello world again';

  // Add this to top level document node
  objDoc.firstChild.appendChild(objNode);

  // Get textual version of xml
  ShowMessage(objDoc.xml);

  // Update the node text
  objNode.text:='Hello world the second time';

  // Get textual version of xml
  ShowMessage(objDoc.xml);

  // Remove the child node
  objDoc.firstChild.removeChild(objNode);

  // Get textual version of xml
  ShowMessage(objDoc.xml);

end;

end.
0
 
SaLzAuthor Commented:
anything better?
0
 
Russell LibbySoftware Engineer, Advisory Commented:
What are you looking for **specifically**?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SaLzAuthor Commented:
something really simple, but workable, that can create a XML for storing settings and data and all that, like functions to be able to Add/Edit/Delete/List.

at the moment, I'm using XMLDocument1 component and using this below to list my data into a listview.

LISTING
=====================
procedure TForm2.OnOpenXML;
var
  XMLFileName:TFileName;
  XMLStartNode:IXMLNode;
  XMLNode:IXMLNode;
begin
  XMLFileName := 'data.xml';
  try

    form2.listview1.Clear;

    XMLDocument1.FileName := XMLFileName;
    XMLDocument1.Active:=True;

    XMLStartNode:=XMLDocument1.DocumentElement.ChildNodes.First.ChildNodes.FindNode('items');
    XMLNode := XMLStartNode;
    repeat


      with form2.listview1.Items.Add do begin
         Caption := ReplaceItem(XMLNode.ChildNodes['ID'].Text);
         SubItems.Add(ReplaceItem(XMLNode.ChildNodes['Name'].Text));
      end;

      XMLNode := XMLNode.NextSibling;

    until XMLNode = nil;

  finally
  XMLDocument1.Active:=false;
  end;

end;
========

SAVING
=========
procedure TForm2.OnSaveXML;
var
i:integer;
begin
form2.memo2.clear;
form2.memo2.lines.Add('<DATA>');
form2.memo2.lines.Add('  <List>');

if form2.listview1.Items.Count = 0 then begin

  form2.memo2.lines.Add('    <items>');
  form2.memo2.lines.Add('      <ID>0</ID>');
  form2.memo2.lines.Add('      <Name>0</Name>');
  form2.memo2.lines.Add('    </items>');

end else begin
for i:= 0 to form2.listview1.Items.Count - 1 do begin

  form2.memo2.lines.Add('    <items>');
  form2.memo2.lines.Add('      <ID>'+ReplaceItem(form2.listview1.items[i].Caption)+'</ID>');
  form2.memo2.lines.Add('      <Name>'+ReplaceItem(form2.listview1.items[i].SubItems[0])+'</Name>');
  form2.memo2.lines.Add('    </items>');

end;

end;
form2.memo2.lines.Add('  </List>');
form2.memo2.lines.Add('</DATA>');

form2.memo2.lines.SaveToFile('data.xml');
end;
===========
 
The Editing & Deleteing Happens in the Listview, but I know that there is a more simple way of adding/deleting/editing/listing of XML data with Delphi or else they wouldn't of put it in there, but no one has any idea of how they work, do u know.

if u know how to do it, could u list in order of how it can be done, not all togeather, but in sections like for ADD, you put the code below add, then Edit, code for that and the Delete, code for that, List, code for that.

do u know how to do it?

Sal.
0
 
SaLzAuthor Commented:
something like a function or something

lets say we have this XML data below..
<DATA>
  <List>
    <items>
      <ID>1</ID>
      <Name>Testing ID 1</Name>
    </items>
    <items>
      <ID>2</ID>
      <Name>Testing ID 2</Name>
    </items>
    <items>
      <ID>3</ID>
      <Name>Testing ID 3</Name>
    </items>
  </List>
</DATA>

a Function could be..
View..
ViewXML(3,'Name'); //the result would be "Testing ID 3".

Delete..
DeleteXML(3,0); //the result would be to delete the hole entry.
also if you wanted to just delete a item then
DeleteXML(3,1); and that would delete the 1 row which is the Name and it will delete that, if it was 0, then it will delete the hole item entry.

Edit..
XMLX('Edit',3,'Name',Testing Completed'); //the result would be to delete the hole entry.

Add..
AddXML(0,0,0);//this will add the entry and return the ID number.

so it could be like
makenewid:=AddXML(0);
AddXML(makenewid,'Name','Adding Done'); //this will add the new name to the newly created item entry.
AddXML(makenewid,'Set','94');

do you understand what I mean??

Sal.


0
 
SaLzAuthor Commented:
Edit..
EditXML(3,'Name','Testing Completed');

even for delete it could be
DeleteXML(3,'Name');

which would probly be easier.
0
 
Russell LibbySoftware Engineer, Advisory Commented:
I understand what you are after now, and that is why I asked for an example:

> "If you have a specific example (xml) that you would like demonstrated then let me know"

Without having something that you can relate to, the code examples become abstract and will not have much meaning. Anyways, give me 20 and I will post back an example project (form code/dfm) that should give you some good ideas.

Russell
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Here is a fully functional program that allows for adding, clearing, deleting, editing (just did the id), saving, loading, finding and more. If you want to simplify it further by writing more utility functions, then I leave that as an exercise for you. But, the functions I have provided should give you a good starting point to go from:

function FindNodeByName(BaseNode: IXMLDOMNode; Name: String): IXMLDOMNode;
function GetItemNode(ListNode: IXMLDOMNode; Index: Integer): IXMLDOMNode;
function FindItemNode(ListNode: IXMLDOMNode; ID, Name: String): Integer;

add form function

function TForm1.GetListNode: IXMLDOMNode;


 Should you have any specific questions, then ask.

Regards,
Russell


// Unit source for form 1

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComObj, ActiveX, MSXML2_TLB, StdCtrls, ComCtrls;

type
  TForm1            =  class(TForm)
     btnAdd:        TButton;
     btnRemove:     TButton;
     btnClear:      TButton;
     btnSave:       TButton;
     btnLoad:       TButton;
     ListView1:     TListView;
     Memo1:         TMemo;
     btnFind:       TButton;
     txtID:         TEdit;
     txtName:       TEdit;
     procedure      FormCreate(Sender: TObject);
     procedure      FormClose(Sender: TObject; var Action: TCloseAction);
     procedure      btnClearClick(Sender: TObject);
     procedure      btnAddClick(Sender: TObject);
     procedure      btnRemoveClick(Sender: TObject);
     procedure      btnSaveClick(Sender: TObject);
     procedure      btnLoadClick(Sender: TObject);
     procedure      btnFindClick(Sender: TObject);
     procedure      ListView1Edited(Sender: TObject; Item: TListItem; var S: String);
  private
     // Private declarations
     FDoc:          IXMLDOMdocument2;
     FNextID:       Integer;
  protected
     // Protected declarations
     function       GetListNode: IXMLDOMNode;
     procedure      Load;
     function       Save: String;
  public
     // Public declarations
  end;

var
  Form1:            TForm1;

implementation
{$R *.DFM}

function FindNodeByName(BaseNode: IXMLDOMNode; Name: String): IXMLDOMNode;
var  objChild:      IXMLDOMNode;
begin

  // Set default
  result:=nil;

  // Get first child
  objChild:=BaseNode.firstChild;

  // Walk the children
  while Assigned(objChild) do
  begin
     // Check name
     if (CompareText(String(objChild.nodeName), Name) = 0) then
     begin
        // Found the node
        result:=objChild;
        // Break out
        break;
     end;
     // Next child
     objChild:=objChild.nextSibling;
  end;

end;

function GetItemNode(ListNode: IXMLDOMNode; Index: Integer): IXMLDOMNode;
var  objItem:       IXMLDOMNode;
     dwIndex:       Integer;
begin

  // Set default
  result:=nil;

  // Check passed list node
  if Assigned(ListNode) then
  begin
     // Set index
     dwIndex:=0;
     // Walk the items in the list
     objItem:=ListNode.firstChild;
     while Assigned(objItem) do
     begin
        // Check node name
        if (CompareText(String(objItem.nodeName), 'Items') = 0) then
        begin
           // Compare index
           if (dwIndex = Index)  then
           begin
              // Found the item
              result:=objItem;
              // Break out
              break;
           end;
           // Increment the index of the node
           Inc(dwIndex);
        end;
        // Next sibling
        objItem:=objItem.nextSibling;
     end;
  end;

end;

function FindItemNode(ListNode: IXMLDOMNode; ID, Name: String): Integer;
var  objItem:       IXMLDOMNode;
     objID:         IXMLDOMNode;
     objName:       IXMLDOMNode;
     dwIndex:       Integer;
begin

  // Default result
  result:=(-1);

  // Check passed list node
  if Assigned(ListNode) then
  begin
     // Set index
     dwIndex:=0;
     // Walk the items in the list
     objItem:=ListNode.firstChild;
     while Assigned(objItem) do
     begin
        // Check item name
        if (CompareText(String(objItem.nodeName), 'Items') = 0) then
        begin
           // Get ID and name node
           objID:=FindNodeByName(objItem, 'ID');
           objName:=FindNodeByName(objItem, 'Name');
           // Check assignment
           if Assigned(objID) and Assigned(objName) then
           begin
              // Compare values (allow for blank to match anything
              if ((ID = EmptyStr) or (CompareText(ID, String(objID.text)) = 0)) and
                 ((Name = EmptyStr) or (CompareText(Name, String(objName.text)) = 0)) then
              begin
                 // Found the item
                 result:=dwIndex;
                 // Break out
                 break;
              end;
           end;
           // Increment the index
           Inc(dwIndex);
        end;
        // Next sibling
        objItem:=objItem.nextSibling;
     end;
  end;

end;

function TForm1.GetListNode: IXMLDOMNode;
var  objData:       IXMLDOMNode;
begin

  // Set default
  result:=nil;

  // Try to get the Data node
  objData:=FindNodeByName(FDoc, 'Data');
  if Assigned(objData) then
  begin
     // Try to get the List node
     result:=FindNodeByName(objData, 'List');
  end;

end;

function TForm1.Save: String;
var  objData:       IXMLDOMNode;
     objList:       IXMLDOMNode;
     objItem:       IXMLDOMNode;
     objID:         IXMLDOMNode;
     objName:       IXMLDOMNode;
     lvItem:        TListItem;
     dwIndex:       Integer;
begin

  // Clear the xml document
  if FDoc.hasChildNodes then FDoc.removeChild(FDoc.firstChild);

  // Create the Data node
  objData:=FDoc.CreateElement('Data');

  // Add to the document
  FDoc.appendChild(objData);

  // Create the list node
  objList:=FDoc.createElement('List');

  // Add to the data element
  objData.appendChild(objList);

  // Now iterate all items in the list view
  for dwIndex:=0 to Pred(ListView1.Items.Count) do
  begin
     // Get the listview item
     lvItem:=ListView1.Items[dwIndex];
     // Create the Items node
     objItem:=FDoc.createElement('Items');
     // Add to the list node
     objList.appendChild(objItem);
     // Create the id node
     objID:=FDoc.createElement('ID');
     // Set the text
     objID.text:=lvItem.Caption;
     // Add to the Items node
     objItem.appendChild(objID);
     // Create the name node
     objName:=FDoc.createElement('Name');
     // Set the text
     if (lvItem.SubItems.Count > 0) then
        objName.text:=lvItem.SubItems[0]
     else
        objName.text:=EmptyStr;
     // Add to the Items node
     objItem.appendChild(objName);
  end;

  // Set result string
  result:=FDoc.xml;

end;

procedure TForm1.Load;
var  objList:       IXMLDOMNode;
     objItem:       IXMLDOMNode;
     objID:         IXMLDOMNode;
     objName:       IXMLDOMNode;
     lvItem:        TListItem;
begin

  // Try to get the List node
  objList:=GetListNode;
  if Assigned(objList) then
  begin
     // Walk the items in the list
     objItem:=objList.firstChild;
     while Assigned(objItem) do
     begin
        // Check item name
        if (CompareText(String(objItem.nodeName), 'Items') = 0) then
        begin
           // Get ID and name node
           objID:=FindNodeByName(objItem, 'ID');
           objName:=FindNodeByName(objItem, 'Name');
           // Create list item
           lvItem:=ListView1.Items.Add;
           // Set caption
           if Assigned(objID) then
              lvItem.Caption:=objID.text
           else
              lvItem.Caption:=EmptyStr;
           // Add subitem
           if Assigned(objName) then
              lvItem.SubItems.Add(String(objName.text))
           else
              lvItem.SubItems.Add(EmptyStr);
        end;
        // Next sibling
        objItem:=objItem.nextSibling;
     end;
  end;

  // Save to memo text
  Memo1.Text:=FDoc.xml;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Set defaults
  FNextID:=1;

  // Create DOM document
  FDoc:=CoDOMDocument.Create;

  // Call save to get the current XML
  Memo1.Text:=Save;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  // Release DOM document
  FDoc:=nil;

end;

procedure TForm1.btnClearClick(Sender: TObject);
begin

  // Clear the list view
  ListView1.Items.BeginUpdate;
  try
     // Clear all items
     ListView1.Items.Clear;
     // Save to memo
     Memo1.Text:=Save;
  finally
     // Unlock list view
     ListView1.Items.EndUpdate;
  end;

end;

procedure TForm1.btnAddClick(Sender: TObject);
var  objList:       IXMLDOMNode;
     objItem:       IXMLDOMNode;
     objID:         IXMLDOMNode;
     objName:       IXMLDOMNode;
     lvItem:        TListItem;
begin

  // Create list view item
  lvItem:=ListView1.Items.Add;

  // Set caption
  lvItem.Caption:=IntToStr(FNextID);

  // Set the subitem text
  lvItem.SubItems.Add(Format('Testing ID %d', [FNextID]));

  // Increment next id
  Inc(FNextID);

  // Try to get the list node
  objList:=GetListNode;
  if Assigned(objList) then
  begin
     // Create the Items node
     objItem:=FDoc.createElement('Items');
     // Add to the list node
     objList.appendChild(objItem);
     // Create the id node
     objID:=FDoc.createElement('ID');
     // Set the text
     objID.text:=lvItem.Caption;
     // Add to the Items node
     objItem.appendChild(objID);
     // Create the name node
     objName:=FDoc.createElement('Name');
     // Set the text
     objName.text:=lvItem.SubItems[0];
     // Add to the Items node
     objItem.appendChild(objName);
  end;

  // Update the memo with the xml text
  Memo1.Text:=FDoc.xml;

end;

procedure TForm1.btnRemoveClick(Sender: TObject);
var  objList:       IXMLDOMNode;
     objItem:       IXMLDOMNode;
     lvItem:        TListItem;
begin

  // Get selected item
  lvItem:=ListView1.Selected;

  // Check item
  if Assigned(lvItem) then
  begin
     // Get list item
     objList:=GetListNode;
     if Assigned(objList) then
     begin
        // Find item by index
        objItem:=GetItemNode(objList, lvItem.Index);
        // Check item
        if Assigned(objItem) then
        begin
           // Remove item from the list node
           objList.removeChild(objItem);
           // If you wanted to remove the ID node from the item, you would do the following
           // objID:=FindNodeByName(objItem, 'ID');
           // if Assigned(objID) then objItem.removeChild(objID);
           // - or for name -
           // objName:=FindNodeByName(objItem, 'Name');
           // if Assigned(objName) then objItem.removeChild(objName);
        end;
     end;
     // Free selected list item
     lvItem.Free;
     // Update memo
     Memo1.Text:=Save;
  end;

end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin

  // Save to test.xml in root of C drive
  FDoc.save('c:\test.xml');

end;

procedure TForm1.btnLoadClick(Sender: TObject);
begin

  if FileExists('c:\test.xml') then
  begin
     ListView1.Items.BeginUpdate;
     try
        ListView1.Items.Clear;
        FDoc.load('c:\test.xml');
        Load;
     finally
        ListView1.Items.EndUpdate;
     end;
  end;

end;

procedure TForm1.btnFindClick(Sender: TObject);
var  dwIndex:    Integer;
begin

  // Find the item
  dwIndex:=FindItemNode(GetListNode, txtID.Text, txtName.Text);

  // Check index
  if (dwIndex >= 0) and (dwIndex < ListView1.Items.Count) then
  begin
     // Set focus and selection
     ListView1.Items[dwIndex].Selected:=True;
     ListView1.Items[dwIndex].Focused:=True;
  end;

end;

procedure TForm1.ListView1Edited(Sender: TObject; Item: TListItem; var S: String);
var  objNode:       IXMLDOMNode;
     objID:         IXMLDOMNode;
begin

  // Get the node
  objNode:=GetItemNode(GetListNode, Item.Index);

  // Check node
  if Assigned(objNode) then
  begin
     // Get ID node
     objID:=FindNodeByName(objNode, 'ID');
     if Assigned(objID) then
     begin
        // Update text of the node
        objID.text:=S;
        // Save to memo
        Memo1.Text:=FDoc.xml;
     end;
  end;

end;

end.

--- dfm code for form1 ---

object Form1: TForm1
  Left = 227
  Top = 123
  Width = 634
  Height = 425
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object btnSave: TButton
    Left = 8
    Top = 96
    Width = 85
    Height = 21
    Caption = 'Save'
    TabOrder = 3
    OnClick = btnSaveClick
  end
  object btnLoad: TButton
    Left = 8
    Top = 124
    Width = 85
    Height = 21
    Caption = 'Load'
    TabOrder = 4
    OnClick = btnLoadClick
  end
  object btnRemove: TButton
    Left = 8
    Top = 40
    Width = 85
    Height = 21
    Caption = 'Remove'
    TabOrder = 1
    OnClick = btnRemoveClick
  end
  object ListView1: TListView
    Left = 100
    Top = 8
    Width = 513
    Height = 150
    Columns = <
      item
        Caption = 'ID'
        Width = 100
      end
      item
        Caption = 'Name'
        Width = 200
      end>
    HideSelection = False
    TabOrder = 5
    ViewStyle = vsReport
    OnEdited = ListView1Edited
  end
  object Memo1: TMemo
    Left = 100
    Top = 164
    Width = 513
    Height = 117
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Courier New'
    Font.Style = []
    Lines.Strings = (
      '<Data>'
      ' <List>'
      ' </List>'
      '<Data>')
    ParentFont = False
    ReadOnly = True
    ScrollBars = ssVertical
    TabOrder = 6
  end
  object btnAdd: TButton
    Left = 8
    Top = 12
    Width = 85
    Height = 21
    Caption = 'Add'
    TabOrder = 0
    OnClick = btnAddClick
  end
  object btnClear: TButton
    Left = 8
    Top = 68
    Width = 85
    Height = 21
    Caption = 'Clear'
    TabOrder = 2
    OnClick = btnClearClick
  end
  object btnFind: TButton
    Left = 8
    Top = 304
    Width = 85
    Height = 21
    Caption = 'Find'
    TabOrder = 7
    OnClick = btnFindClick
  end
  object txtID: TEdit
    Left = 104
    Top = 304
    Width = 77
    Height = 21
    TabOrder = 8
  end
  object txtName: TEdit
    Left = 188
    Top = 304
    Width = 229
    Height = 21
    TabOrder = 9
  end
end


 
0
 
SaLzAuthor Commented:
I looked at the above tryed it and I'm stumped, I donno where everything goes, so I though, ok back to work, cos I've already posted a XML question before and I didn't quite get what I wanted, so I just made my own XML Data with Add/Edit/Delete/List.

from what I thought about the Functions that I posted before. I saw what I wanted in a Function AddXML(ID,Name,Data); and I worked backwords to make it happen.

now I've made the XML Functions with the following..

to Add a New Entry I made it so it goes like this.

XMLValue:=AddXML('0','0','0');//this will add a new entry with 0 fields. it will also return the number of Items in the XML if its founds none then it will be ID 1.

then we make a Field in entry 1 with the following
AddXML(XMLValue,'Field1',Data1');//this will add a new field in id 1 with the name and data.

so a fully adding function looks like this..
=====
XMLValue:=AddXML('0','0','0');
AddXML(XMLValue,'Field1',Data1');
AddXML(XMLValue,'Field2',Data2');
AddXML(XMLValue,'Field3',Data3');

and thats a new Item filled with Fields, if we only want to return the Item count then we just do this.

XMLValue:=AddXML('0','','');//this will return the Item count and nothing else.
====

for Editing, I've made it so it does it like this..
====
EditXML(ID,Field,Data);//this will now edit at the ID on the Field Name with the new Data.

so a fully editing function looks like this..

EditXML('1','TestingField1','Working');//this will edit ID 1 at the given named field and will change the data to the new data.
====

now for delete, I've made it so it does it like this..
====
DeleteXML(ID,Field);

there are 3 elements with this one, so as follows..

DeleteXML('1','');//this will delete the ID 1 Entry and all of its fields.
DeleteXML('1','TestingField1');//this will delete only the field that is selected.
DeleteXML('Perge','All');//will delete all Items in the XML so its empty.
===

now onto Listing, I've made it so it does it like this..
===
ListXML(ID,Field);//this will get the Data with the use of the ID and Field Name and will return the Data.

so a fully listing function looks like this.

for i:=1 to AddXML('0','','') do begin

memo1.lines.Add('ID:='+inttostr(i)+' Name='+ListXML(inttostr(i),'Name'));
memo1.lines.Add('ID:='+inttostr(i)+' Data='+ListXML(inttostr(i),'Data'));

end;
===


and thats my XML Functions.
AddXML(ID,'Field',Data');
DeleteXML(ID,Field);
EditXML(ID,Field,Data);
ListXML(ID,Field);

so if I wanted to do something like a buttonclick I'd do something like this
============
procedure TForm1.Button1Click(Sender: TObject);
var
ItemCount:string;
begin
//we make our first entry..
ItemCount:=AddXML('0','0','0');
//will now fill the new entry with fields..
AddXML(ItemCount,'Field1','Data1');
AddXML(ItemCount,'Field2','Data2');
AddXML(ItemCount,'Field3','Data3');
AddXML(ItemCount,'Field4','Data4');
AddXML(ItemCount,'Field5','Data5');
Showmessage('Done Adding');
//now that we have added the new fields with the data, lets edit..
EditXML(ItemCount,'Field1','EditedData1');
EditXML(ItemCount,'Field2','EditedData2');
EditXML(ItemCount,'Field3','EditedData3');
EditXML(ItemCount,'Field4','EditedData4');
EditXML(ItemCount,'Field5','EditedData5');
Showmessage('Done Editing');
//editing done, now lets delete a couple of fields..
DeleteXML(ItemCount,'Field4');
DeleteXML(ItemCount,'Field5');
Showmessage('Done Deleting');
//finished deleteing the 2 fields, now lets list the remaining fields.
Memo1.lines.add('Field1:' +ListXML(ItemCount,'Field1'));
Memo1.lines.add('Field2:' +ListXML(ItemCount,'Field2'));
Memo1.lines.add('Field3:' +ListXML(ItemCount,'Field3'));
Showmessage('Done Listing');
end;
============

and thats a fully working XML Function :D I should give my self 500 Points :D

what do u think of it? am I missing anything? if so I can add it if its worth adding, but at the moment, I got all them 4 Functions working insink, with out errors.

am pritty chuffed really, :D I've made a XML Function that is so easy to work with.

cos when I look at that code you posted I was like :-O this is gonna take a wile to figure all this out, I tested it and though this is 2 much work, so made me own, which is above :D

the hole 4 Functions only comes to 87 Lines of Code :D plus I've put it into a pas file.

a simple XML Function, I've seen all the others XML Functions and its like node this and node that, it was 2 much, small functions are the best.

am going to bed now, 99.

Sal.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Close the question then, and best of luck in the future.

0
 
Russell LibbySoftware Engineer, Advisory Commented:

Post your question for deletion here:

http://www.experts-exchange.com/Community_Support
0
 
SaLzAuthor Commented:
nah its fine you got the points, you pushed me into making this function by posting your sample which was 2 much for me, far 2 much work.

the best thing about this XML Function is that it doesn't use any components or anything, its just a function for the 4 Entrys.

I couldn't beleave how simple it was, when I figured out how everything slotted togeather, it mimics the XML usage in a way which is simplier, doesn't use any of the components like nodes and stuff, just plain function contents.

thanks for your help tho, if I didn't see your example, I'd probly not have made my own function, in seeing all what you put made me think there must be a easier way, cos its only ID, Field, Data, only them 3 make up xml database. simplisity is the key.

am still hiped about it, cos its just so simple and highly effective function for XML, I've been searching for months and asked 2questions on XML, and finally making my own to tailer to my needs.

Thanks for giving me a Push to make the function :D been longing for a database which was easier.

Sal.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now