Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   xml Nodes Attribute lesen (https://www.delphipraxis.net/211465-xml-nodes-attribute-lesen.html)

Pfaffe 20. Sep 2022 07:02

xml Nodes Attribute lesen
 
Ich habe eine BMECAT xml und möchte per TXMLDocument PRICE_FLAG lesen.
Mit s:= LNodeElement_CATALOG.ChildNodes.FindNode('PRICE_FL AG').Text; komme ich an das erste PRICE_FLAG, welches "false" ist.
Mit s:= LNodeElement_CATALOG.ChildNodes.FindNode('PRICE_FL AG').AttributeNodes['type'].Text; komme ich an das erste Attribut, welches "incl_assurance" lautet.
Wie aber komme ich an die weiteren drei PRICE_FLAG's?

<?xml version="1.0" encoding="UTF-8"?>
<BMECAT version="2005">
<HEADER>
<CATALOG>
<LANGUAGE>deu</LANGUAGE>
<CATALOG_ID>2021</CATALOG_ID>
<CATALOG_VERSION>09</CATALOG_VERSION>
<CATALOG_NAME>Produktkatalog</CATALOG_NAME>
<TERRITORY>DE</TERRITORY>
<CURRENCY>EUR</CURRENCY>
<PRICE_FLAG type="incl_assurance">false</PRICE_FLAG>
<PRICE_FLAG type="incl_duty">true</PRICE_FLAG>
<PRICE_FLAG type="incl_packing">false</PRICE_FLAG>
<PRICE_FLAG type="incl_freight">false</PRICE_FLAG>
</CATALOG>

bcvs 20. Sep 2022 07:30

AW: xml Nodes Attribute lesen
 
Ich würde das anders angehen und durch die Nodes iterieren:
Delphi-Quellcode:
var Node:IXMLNode;

Node:= LNodeElement_CATALOG.ChildNodes.First;
while Node<>nil do
begin
  if Node.NodeName = 'PRICE_FLAG' then
  begin
    if Node.Attributes['type'] = 'incl_assurance' then
      ...
    else if Node.Attributes['type'] = 'incl_duty' then
      ...
  end;
  Node := Node.NextSibling;
end;
(nicht getestet)

Pfaffe 20. Sep 2022 08:03

AW: xml Nodes Attribute lesen
 
Danke, funktioniert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:54 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