?
Solved

Delphi MSXML

Posted on 2006-04-26
2
Medium Priority
?
1,998 Views
Last Modified: 2012-05-05
Hi,
I am parsing XML documents using MSXML_TLB. For example if the xml is

 <message>
  <messtime>19:14</messtime>
  <messdate>2006-04-21</messdate>
  <status code="63">On route to delivery branch</status>
 </message>

i can get "On route to delivery branch" using
  oNodeList := oXMLDoc.selectNodes('//message');
  listbox1.Items.Add(oNodeList[0].text);

But i don't know how to get the "code" value which is 63 for this example. if I use it like this
  oNodeList := oXMLDoc.selectNodes('//status );
  listbox1.Items.Add(oNodeList[0].text);

it returns "On route to delivery branch"

thanks in advance
0
Comment
Question by:bilgehanyildirim
2 Comments
 
LVL 1

Accepted Solution

by:
nou68 earned 2000 total points
ID: 16544944
Try this
procedure TForm1.Button1Click(Sender: TObject);
var

  FDOM      : IXMLDOMDocument;
   amsg: string;
  FRootEL        : IXMLDOMElement;
  FEL   : IXMLDOMNode;
  AnyElement: string;
  aVariant: variant;

begin
  amsg := memo1.text;
  FDOM := CoDOMDocument.Create;
  if not FDOM.loadXML(aMsg) then
   raise Exception.Create('Invalid XML message');

  AnyElement := 'status';
   FrootEL := FDOM.DocumentElement;
   FEl   := FrootEL.selectSingleNode('./' + AnyElement);

   if FEl <> nil  then
   begin
     aVariant :=  (FEl As IXMLDOMElement).getAttribute('code');

     if not varisNull(aVariant) then
       ShowMessage(aVariant);

   end;

end;
0
 

Author Comment

by:bilgehanyildirim
ID: 16545361
that's it!! Thank you very much.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 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