GARANTIR DESCONTO

Fórum exportar de .xml para .txt usando TXmlDocument #414340

20/03/2012

0

Colegas, boa noite.

Tenho esse código abaixo que consigo jogar em um treview um arquivo .xml:



uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,
xmldom,XMLIntf,msxmldom,XMLDoc,ComCtrls,ActiveX,StdCtrls,ExtCtrls;


type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
twXML: TTreeView;
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure SetFXML(const Value: string);
procedure GenereteTree(XMLNode: IXMLNode; TreeNode: TTreeNode);
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
FXML: String;
origem: String;
implementation

{$R *.dfm}

procedure TForm1.SetFXML(const Value: string);
var
oXML: TXMLDocument;
begin
FXML := Value;

if not FileExists(FXML) then
raise Exception.Create(Arquivo + FXML + , não encontrado);

Caption := Consulta NFe + ExtractFileName(FXML);

coInitialize(nil);
oXML := TXMLDocument.Create(Self);
oXML.LoadFromFile(FXML);
oXML.Active := true;

twXML.Items.Clear;

GenereteTree(oXML.DocumentElement.ChildNodes.First, nil);

twXML.ReadOnly := true;
twXML.AutoExpand := true;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SetFXML(H:\exportTXT\teste.xml);
end;

procedure Tform1.GenereteTree(XMLNode: IXMLNode; TreeNode: TTreeNode);
var
NodeText: string;
NewTreeNode: TTreeNode;
I: integer;
begin
if XMLNode.NodeType <> ntElement then
Exit;
NodeText := XMLNode.NodeName;
if XMLNode.IsTextElement then
NodeText := NodeText + = + XMLNode.NodeValue;
NewTreeNode := twXML.Items.AddChild(TreeNode, NodeText);
if XMLNode.HasChildNodes then
for I := 0 to XMLNode.ChildNodes.Count - 1 do
GenereteTree(XMLNode.ChildNodes[I], NewTreeNode);
end;

end.

O que preciso e de em vez de jogar em um treview, exportar para um arquivo .txt. Alguem poderia me ajudar?

Só lembrando esse código consegui com um colega em outro form.

Grato:
Jose Luiz
Jose Medeiros

Jose Medeiros

Responder

Posts

20/03/2012

Bruno Leandro

veja se o conteudo desta propriedade atende as suas necessidades, XMLDocument.XML.Text
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar