EricTaylor
asked on
reading XLM file in Delphi (IXMLDocument) not working
I'm successfully writing an XML document with IXMLDocument which, slightly simplified, looks like this:
<?xml version="1.0"?>
<Email>
<Subject>3 events scheduled starting 3/13 1:30 PM: Job 1034</Subject>
<DeptID>111</DeptID>
<sPersonIDs>10240; 175</sPersonIDs>
<MessageText>3/11, 3/12, 3/13 1:30 - 5:00 PM Water Damage Assigned to: Bilbo Baggins</MessageText>
</Email>
My attempt to read the file looks like this:procedure TChronEmail.GetFromTempFile;
var
i:integer;
sFile : string;
Doc: IXMLDocument;
Email: IXMLNode;
begin
sFile := [filename--I've tested that it is valid and that it is there];
if fileExists(sFile) then begin
Doc.LoadFromFile(sFile);
i := 0; // for this test, only need the first entry in the file
Email := DOC.ChildNodes.Nodes['Email'].ChildNodes[i];
Subject := Email.ChildNodes['Subject'].Text;
if tryStrToInt(Email.ChildNodes['DeptID'].Text, i) then DeptID := i;
sPersonIDs := Email.ChildNodes['sPersonIDs'].Text;
MessageText := Email.ChildNodes['MessageText'].Text;
Apparently I'm missing something important since I'm not getting any values back out of my file. This is my first time working with IXMLDocument/IXMLNode, so happy for any guidance. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note: some XPathing might also get you the first Email item.
ASKER
Thanks. That did the trick and now I understand how the pieces are relating here.
I didn't understand the XPathing comment though; would appreciate if you would clarify to give me a better understanding.
I didn't understand the XPathing comment though; would appreciate if you would clarify to give me a better understanding.
@EricTaylor
Maybe it would be better if I point you at some instructional material on XPath to get you up to speed.
http://www.w3schools.com/XPath/ (tutorial)
http://www.w3schools.com/xpath/xpath_syntax.asp (syntax)
Since we're in a Delphi development environment, you would probably benefit from seeing some Delphi code examples that use XPath.
http://delphi.about.com/od/vclusing/qt/delphi-select-xml-nodes-ixmlnodelist-selectnodes-xpath-xmldom.htm (Delphi example)
http://keith-wood.name/DelphiXML/BookCode/ (lots of Delphi examples in this ebook/article)
If you are still stuck after playing with this, you can ask a new question about XPathing and your Delphi code.
Maybe it would be better if I point you at some instructional material on XPath to get you up to speed.
http://www.w3schools.com/XPath/ (tutorial)
http://www.w3schools.com/xpath/xpath_syntax.asp (syntax)
Since we're in a Delphi development environment, you would probably benefit from seeing some Delphi code examples that use XPath.
http://delphi.about.com/od/vclusing/qt/delphi-select-xml-nodes-ixmlnodelist-selectnodes-xpath-xmldom.htm (Delphi example)
http://keith-wood.name/DelphiXML/BookCode/ (lots of Delphi examples in this ebook/article)
If you are still stuck after playing with this, you can ask a new question about XPathing and your Delphi code.
ASKER
thanks :)
Is the childnode array dimensioned from 0 or 1?
mlmcc