Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an XML attribute's value?

Tags:

xml

delphi

Given the XML snippet below, how can I get the value of the XML attribute TEXT?

<POPULARITY URL="example.com"  SOURCE="panel" TEXT="27503270" />

Negative...

MY CODES...:

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
   if kontrol=0 then
   begin
      XMLDocument1.Active:=false;
      XMLDocument1.FileName:='http://data.alexa.com/data?cli=10&dat=snbamz&url=aliatabak.com';
      XMLDocument1.Active:=true;
   end;
   i:=1;
   baslangic:=XMLDocument1.DocumentElement.ChildNodes.FindNode('SD');
   repeat
      isim:=baslangic.ChildNodes.Nodes['??????'].Text;

      edit1.Text:=isim;

      i:=i+1;
      baslangic:=baslangic.NextSibling;
   Until baslangic=nil;

end;
like image 658
user1424940 Avatar asked Nov 29 '25 23:11

user1424940


1 Answers

Use the IXMLNode.Attributes property:

isim := VarToStr(baslangic.Attributes['TEXT']);

Or the IXMLNode.AttributeNodes property:

Isim := baslangic.AttributeNodes.Nodes['TEXT'].Text;

Or:

Attr := baslangic.AttributeNodes.FindNode('TEXT');
If Attr <> nil then
    isim := Attr.Text;
like image 66
Remy Lebeau Avatar answered Dec 01 '25 13:12

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!