Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   XML (https://www.delphipraxis.net/46-xml/)
-   -   komische XML auslesen (https://www.delphipraxis.net/197088-komische-xml-auslesen.html)

arnof 17. Jul 2018 08:57

komische XML auslesen
 
Hallo,

ich habe folgenden XML Aufbau:

Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<artlist>
<art eid="1442163" fab="140.20.01"/>
<art eid="1442164" fab="140.20.02"/>
<art eid="2341594" fab="142.20.01"/>
</artlist>
Irgendwie sieht das ja nicht ganz so aus, wie man eine XML machen würde ....

Nun lese ich das ein und will die Infos auslesen:

Delphi-Quellcode:
XMLDocument1.Active:=False;
  XMLDocument1.XML.Text:=xml;
  XMLDocument1.Active:=True;
  LNodeElement := XMLDocument1.ChildNodes.FindNode('artlist');
  if (LNodeElement <> nil) then begin

   xxxxx

  end;
hier fehlt mir der nächste Schritt, wie es mit TXMLDocument weiter geht :oops:

Aviator 17. Jul 2018 09:00

AW: komische XML auslesen
 
Eigentlich ist das schon XML. Schau dir mal Attribute an. Damit solltest du weiter kommen.

EDIT:

Hier mal ein kleines Beispiel wie man darauf zugreifen kann:

Delphi-Quellcode:
  if (XmlNode.HasAttribute('active')) then begin
    Temp := XmlNode.Attributes['active'];
    Result.Active := StrToBool(Temp);
  end;
EDIT 2:

Sorry übersehen. Am Besten nutzt du
Delphi-Quellcode:
IXMLDocument
und dann

Delphi-Quellcode:
var
  Doc: IXMLDocument;
begin
  Doc := LoadXMLDocument(FFileName);
end;
Hierfür müsstest du noch die Units:
Delphi-Quellcode:
Xml.XMLIntf, Xml.XMLDoc
einbinden.

arnof 17. Jul 2018 10:10

AW: komische XML auslesen
 
Dank für den Hilfe, ich habe es aber nun, wie es geht:

Delphi-Quellcode:
  XMLDocument1.Active:=False;
  XMLDocument1.XML.Text:=xml;
  XMLDocument1.Active:=True;
  LNodeElement := XMLDocument1.ChildNodes.FindNode('artlist');
  if (LNodeElement <> nil) then begin
    LNode:=LNodeElement.ChildNodes.First;
    TGrid_ArtList.RowCount:=LNodeElement.ChildNodes.Count+1;
    zeile:=1;
    while LNode<>nil do begin
       s:= LNode.NodeName;
       if (LNode.HasAttribute('eid')) then begin
        LAttrValue := LNode.Attributes['eid'];
        TGrid_ArtList.Cells[1,zeile]:=LAttrValue;
       end;
       if (LNode.HasAttribute('fab')) then begin
        LAttrValue := LNode.Attributes['fab'];
        TGrid_ArtList.Cells[2,zeile]:=LAttrValue;
       end;
       if zeile<LNodeElement.ChildNodes.Count then begin
        LNode := LNodeElement.ChildNodes.Get(Zeile);
       end else LNode:=nil;
       inc(zeile);
    end;
  end;
  XMLDocument1.Active:=False;


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:58 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz