meta data for this page
  •  

Working with XML data

The following set of functions have been implemented to read data from XML files:

The following example illustrates how to use ibec_msxml_xxx functions to process XML data. Detailed descriptions of these functions will come soon.

Example

  execute ibeblock
  as
  begin
    UserDB = ibec_GetUserDBConnection();
    if (UserDB is null) then
    begin
      ibec_ShowMessage('You have to use the IBExpert User Database.' + ibec_CRLF() +
                       '(Options | Environment Options | User Database)');
      Exit;
    end;
 
    ibec_UseConnection(UserDB);


    xmlfile = 'https://www.ibexpert.com/rus/ibedemoscripts.xml';
    --xmlfile = 'w:\ibedemoscripts.xml';
    xml = ibec_msxml_Create();
    try
      ibec_msxml_Load(xml, xmlfile);
      nodes = ibec_msxml_SelectNodes(xml, 'demoscripts/script');

      foreach (nodes as node skip nulls) do
      begin
        sid = ibec_msxml_GetAttribute(node, 'id');
        sorder = ibec_msxml_GetAttribute(node, 'order');
        stype = ibec_msxml_GetAttribute(node, 'type');
        sparent = ibec_msxml_GetAttribute(node, 'parentid');

        tempnode = ibec_msxml_SelectSingleNode(node, 'name');
        if (tempnode is not null) then
          sname = ibec_msxml_GetText(tempnode);

        tempnode = ibec_msxml_SelectSingleNode(node, 'description');
        if (tempnode is not null) then
          sdesc = ibec_msxml_GetText(tempnode);

        tempnode = ibec_msxml_SelectSingleNode(node, 'source');
        if (tempnode is not null) then
          ssource = ibec_mime_Decode(ibec_msxml_GetText(tempnode));

        if (exists(select id from ibescripts where id = :sid)) then
          update ibescripts
          set item_order = :sorder,
              item_type = :stype,
              item_parent_id = :sparent,
              item_name = :sname,
              item_description = :sdesc,
              item_source = :ssource
          where id = :sid;
        else
          insert into ibescripts (id, item_order, item_type, item_parent_id, item_name, item_description, item_source)
                      values (:sid, :sorder, :stype, :sparent, :sname, :sdesc, :ssource);
        commit;
      end

    finally
      ibec_msxml_Free(xml);
    end;
  end