Steve,
I suggest you read the MSXML SDK that comes with MSXML.
A few observations:
a) If you are using MsXML 6 then you should be using iXmlDomDocument3
instead of iXmlDomDocument
b) I don't recall RootNode as property of iXmldomdocument. The first
element is documentElement.
c) If you want the value of "result" then you can use a
SelectSingleNode method - cNode:= doc.selectSingleNode('//result') where
cNode must be declared as iXmlDomNode; If cNode <> nil, then the value
is then cnode.NodeValue;
d) The nodename is "result" not "success" in your pseudocode.
Hope this helps.
KK Aw
On 1/26/2011 5:43 PM, Steve Bowker wrote:
Hi,
Has anyone had any experience of using Delphi (5)& MSXML? I can't seem to
find any decent example code or tutorials on Google.
I've got as far as receiving the XML via a client socket, so have the XML as
one long string.
Here is the sample XML as it would look in text format:
<query>
<result>success</result>
<id>01234567890</id>
<balance>54.50</balance>
<tickets>320</tickets>
<holder_title>Mr</holder_title>
<holder_firstname>Steve</holder_firstname>
<holder_surname>Smith</holder_surname>
</query>
The 1st element after<query> will always be<result> and if 'success' it is followed by the
returned elements above, else it will return elements containing<failcode> & <failreason>
Here's the (not very elegant) pseudo code of what I want to do with this, can
anyone provide the actual Delphi(5) code to acheive this?
uses
MSXML2_TLB;
procedure ProcessAllelementsFromXML;
var
ElementName, ElementValue: string;
Doc: IXMLDOMDocument;
begin
Doc := CoDOMDocument.Create;
if Doc.LoadXML(strXML) then
begin
if Doc.RootNode = '<query>' then
begin
for i := 0 to NumberOfElementsWithinQueryNode do
begin
ElementName := Doc.ElementName[i];
ElementValue := Doc.ElementValue[i];
if ElementName = 'success' then
carry on with loop and populate some text fields from ElementName&
Value
else
carry on with loop and process each<failcode> & <failreason>
end;
end
else if Root Node = 'adjust' then
begin
as above but different element names are processed slightly differently
end;
end;
end;
Thanks in advance for any help,
Steve
_______________________________________________
Delphi mailing list
Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi