[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1547
  • Last Modified:

Retrieve E-mail address from XML (text) file

Hi,

I need to retrieve the E-mail address (which is stored under <SMTP_Email_Address....) from the XML-file below.
Can anybody help me to write a function for this?


<?xml version="1.0" encoding="utf-16" ?>
<MessageAccount>
    <Account_Name type="SZ">MyName</Account_Name>
    <Connection_Type type="DWORD">00000003</Connection_Type>
    <Make_Available_Offline type="DWORD">00000001</Make_Available_Offline>
    <IMAP_Port type="DWORD">0000008f</IMAP_Port>
    <IMAP_Timeout type="DWORD">0000003c</IMAP_Timeout>
    <IMAP_Use_LSUB type="DWORD">00000001</IMAP_Use_LSUB>
    <IMAP_Polling type="DWORD">00000001</IMAP_Polling>
    <IMAP_Svr-side_Special_Folders type="DWORD">00000001</IMAP_Svr-side_Special_Folders>
    <IMAP_Sent_Items_Folder type="SZ">Verzonden items</IMAP_Sent_Items_Folder>
    <IMAP_Drafts_Folder type="SZ">Concepten</IMAP_Drafts_Folder>
    <IMAP_Prompt_for_Password type="DWORD">00000000</IMAP_Prompt_for_Password>
    <IMAP_Dirty type="DWORD">00000000</IMAP_Dirty>
    <IMAP_Poll_All_Folders type="DWORD">00000001</IMAP_Poll_All_Folders>
    <POP3_Server type="SZ">pop.mypop.nl</POP3_Server>
    <POP3_User_Name type="SZ">myemail@mypop.nl</POP3_User_Name>
    <POP3_Password2 type="BINARY">01000000d08c9dfger6784etc.</POP3_Password2>
    <POP3_Port type="DWORD">0000006e</POP3_Port>
    <POP3_Secure_Connection type="DWORD">00000000</POP3_Secure_Connection>
    <POP3_Timeout type="DWORD">0000003c</POP3_Timeout>
    <Leave_Mail_On_Server type="DWORD">00000001</Leave_Mail_On_Server>
    <Remove_When_Deleted type="DWORD">00000001</Remove_When_Deleted>
    <Remove_When_Expired type="DWORD">00000001</Remove_When_Expired>
    <Expire_Days type="DWORD">00000005</Expire_Days>
    <POP3_Skip_Account type="DWORD">00000000</POP3_Skip_Account>
    <POP3_Prompt_for_Password type="DWORD">00000000</POP3_Prompt_for_Password>
    <SMTP_Server type="SZ">smtp.mypop.nl</SMTP_Server>
    <SMTP_User_Name type="SZ">#smtp.mypop.nl</SMTP_User_Name>
    <SMTP_Use_Sicily type="DWORD">00000000</SMTP_Use_Sicily>
    <SMTP_Port type="DWORD">00000019</SMTP_Port>
    <SMTP_Secure_Connection type="DWORD">00000000</SMTP_Secure_Connection>
    <SMTP_Timeout type="DWORD">0000003c</SMTP_Timeout>
    <SMTP_Display_Name type="SZ">My Name</SMTP_Display_Name>
    <SMTP_Email_Address type="SZ">myname@mypop.nl</SMTP_Email_Address>
    <SMTP_Prompt_for_Password type="DWORD">00000000</SMTP_Prompt_for_Password>
</MessageAccount>

Thank you very much for your help.
Stef
0
Stef Merlijn
Asked:
Stef Merlijn
  • 4
  • 4
1 Solution
 
2266180Commented:
well, yuo will be using some xml component. for example on using TXMLDocument (comes with delphi, see this:

procedure TForm1.FormCreate(Sender: TObject);
var xml:TXmlDocument; node:IXMLNode;
begin
  xml:=TXMLDocument.Create(self);
  xml.DOMVendor:=DomVendors.Vendors[1];// 0 is ms xml and it's stupid :D
  xml.LoadFromFile('c:\data.xml');
  xml.Active:=true;
  node:=xml.DocumentElement.ChildNodes.FindNode('SMTP_Email_Address');
  if node<>nil then showmessage(node.NodeValue)
               else showmessage('not found');
  xml.free;
end;

you will not be able to use teh default vendor in this case since it seems to have some issues swithing from default utf-8 encoding to utf-16. but since it's made by MS it is a "normal" thing :)
0
 
2266180Commented:
oh, you put that XML in a file called c:\data.xml. OR you place it in a stream and pass the stream to loadfromstream. OR you place it in astring and assign the xml.xml.text:=the string..
0
 
Stef MerlijnDeveloperAuthor Commented:
I put your code in the procedure for Button1.

But xml.LoadFromFile(ExtractFilePath(Application.ExeName)+'Test.xml');  gives an accessviolation.
Any ideas?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
2266180Commented:
post the entire code from button click
0
 
Stef MerlijnDeveloperAuthor Commented:
I already got the solution.
xml.DOMVendor:=DomVendors.Vendors[1];
had to be set to
xml.DOMVendor:=DomVendors.Vendors[0];
0
 
2266180Commented:
hm.. weird.
on my sistem xml.DOMVendor:=DomVendors.Vendors[0]; gives an error with the encoding. anyway, if it works, it's good so you can remove that line.
0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you for your help.
The XML-file is used in Windows Vista to store E-mail accounts (*.oeaccount). Maybe that's why the 0 in stead of 1?
Anyway it works perfectly.
0
 
Stef MerlijnDeveloperAuthor Commented:
For other people who are interested in this code:
You should also add following units to the uses clause: XMLDOC, XMLIntf, XMLDom
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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