Solved

Retrieve E-mail address from XML (text) file

Posted on 2006-11-29
8
1,474 Views
Last Modified: 2007-12-19
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
Comment
Question by:Delphiwizard
  • 4
  • 4
8 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 18035902
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
 
LVL 28

Expert Comment

by:2266180
ID: 18035905
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
 

Author Comment

by:Delphiwizard
ID: 18036026
I put your code in the procedure for Button1.

But xml.LoadFromFile(ExtractFilePath(Application.ExeName)+'Test.xml');  gives an accessviolation.
Any ideas?
0
 
LVL 28

Expert Comment

by:2266180
ID: 18036035
post the entire code from button click
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Delphiwizard
ID: 18036036
I already got the solution.
xml.DOMVendor:=DomVendors.Vendors[1];
had to be set to
xml.DOMVendor:=DomVendors.Vendors[0];
0
 
LVL 28

Expert Comment

by:2266180
ID: 18036043
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
 

Author Comment

by:Delphiwizard
ID: 18036094
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
 

Author Comment

by:Delphiwizard
ID: 18036163
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now