Board index » delphi » Problems with IDOMNode

Problems with IDOMNode


2005-04-22 05:03:24 PM
delphi170
Can anyone show me how to get the text out of an IDOMNode ? I can get to the
node using "SelectNode" but am not sure how to extract the data. I am using
Delphi 7 Enterprise with SP 2 on XP SP2.
procedure TForm1.FormCreate(Sender: TObject);
begin
m_XML := '<?xml version="1.0" encoding="windows-1252"?>' +
'<Comms Version="1.0">' +
' <MyNotify>' +
' <AReport Date="2005-04-11" Time="16:23:22"
DateTime="2005-04-11T16:23:22Z">' +
' <CardNumber><![CDATA[966607050]]></CardNumber>' +
' </AReport>' +
' </MyNotify>' +
'</Comms>' ;
end;
procedure TForm1.Button1Click (Sender : TObject) ;
var
theDocument : IXMLDocument ;
ndSelect : IDOMNodeSelect ;
ndNode : IDOMNode ;
begin
theDocument := TXMLDocument.Create (nil) ;
theDocument.LoadFromXML (m_XML) ;
ndSelect := theDocument.DocumentElement.DOMNode as IDOMNodeSelect ;
ndNode := ndSelect.selectNode ('/Comms/MyNotify/AReport/CardNumber') ;
if ndNode <>nil then
begin
// Get the card number from ndNode, but how ?
end ;
end ;
 
 

Re:Problems with IDOMNode

Ian Munro is rumoured to have said:
Quote
Can anyone show me how to get the text out of an IDOMNode ? I can get
to the node using "SelectNode" but am not sure how to extract the
data. I am using Delphi 7 Enterprise with SP 2 on XP SP2.
You could iterate its child text nodes, string them together, and raise
an exception if you find any non-text child nodes. it is a bit awkward.
-tor