EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Copy one part of xml into new xml

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#15719
Posted: 02/10/2011 04:07:24
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

Hello!

I need some help. I want to copy one part of xml into new xml file.
The code so far is
Code
  FileName1:=DirERacunTemp+'\TS_TEST.xml';
  FileName:=WDatoteka;
  F := TFileStream.Create(FileName, fmOpenRead);
  FXMLDocument := TElXMLDOMDocument.Create;
  FXMLDocument2 := TElXMLDOMDocument.Create;
  FXMLDocument.LoadFromStream(F, 'utf-8',true);
  FreeAndNil(F);

  Node:=FXMLDocument.GetElementByID('TimeStampToken');

  FXMlDocument2.ImportNode(Node,true);

  F1 := TFileStream.Create(FileName1, fmCreate or fmOpenWrite);
  FXMLDocument2.SaveToStream(F1, xcmNone, 'utf-8');
  FreeAndNil(F1);


As far I read help the ImportNode should copy the node with sub-nodes. But new xml is empty. Where am I wrong?
Thanks for helping.

Sašo
#15720
Posted: 02/10/2011 04:21:36
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

I think you should use FindChildElementByLocalName instead of FXMLDocument.GetElementByID.
#15721
Posted: 02/10/2011 04:29:50
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

I can't find that function. Could you tell me where is it?

Sašo
#15722
Posted: 02/10/2011 04:34:18
by Vsevolod Ievgiienko (EldoS Corp.)

It is located in SBXMLUtils unit. The code will look like this:

using SBXMLUtils;
...
Node := FindChildElementByLocalName(FXMLDocument, 'TimeStampToken');
#15723
Posted: 02/10/2011 04:53:29
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

I have changed to search by id and it is the same. Xml file has only one line.

Code is
Code
var    Node: TElXMLDOMNode;
    Node:=SBXMLUtils.FindElementById(FXMLDocument.DocumentElement,'TimeStampToken');
#15724
Posted: 02/10/2011 05:11:35
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

Node is found but not inserted into new xml. That is my problem.
#15725
Posted: 02/10/2011 06:08:58
by Vsevolod Ievgiienko (EldoS Corp.)

Could you please post the XML file here.
#15726
Posted: 02/10/2011 06:12:31
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

In attachment.


[ Download ]
#15727
Posted: 02/10/2011 06:20:53
by Vsevolod Ievgiienko (EldoS Corp.)

Use this code to import the node:

FXMlDocument2.AppendChild(FXMlDocument2.ImportNode(Node, true));
#15728
Posted: 02/10/2011 06:27:25
by Sašo Osenk (Standard support level)
Joined: 09/20/2010
Posts: 35

Thank you. Your support is the best.

Sašo
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 1841 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!