Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Attribute auslesen nicht möglich

  Alt 3. Sep 2015, 11:21
Ich bin in XML, insbesondere XPath, nicht wirklich fit. Ich hatte mir einmal einen TXPathHelper gebaut: http://www.delphipraxis.net/1236534-post4.html

Damit kommt man an folgendes Ergebnis:
Code:
Attributes of /.//Jump/not_expected/debugMessages:
type = E

Attributes of /.//Jump/force/Fly:
WDS_FROM_PAGE = XXX
TEST1 = 123
TEST2 = 456

Attributes of /.//Fly/expected/LifeMessages:
type = F
code = IN_HEAVEN
parameterName = DUMMY_PAGE
Mit folgendem Code:
Delphi-Quellcode:
procedure justXmlThings();
const
   paths: TArray<String> = [
      '/.//Jump/not_expected/debugMessages',
      '/.//Jump/force/Fly',
      '/.//Fly/expected/LifeMessages'
   ];
var
   xmlDoc: IXMLDocument;
   path: String;
   node: IXmlNode;
begin
   xmlDoc := LoadXMLData(content);

   for path in paths do begin
      node := TXpathHelper.SelectNode(xmlDoc.Node, path);
      if Assigned(node) then begin
         WriteLn('Attributes of ', path,':');
         printAttributes(node);
         WriteLn(sLineBreak);
      end;
   end;
end;

procedure printAttributes(ofNode: IXMLNode);
var
   attributeIndex:   Integer;
   attribute:      IXMLNode;
begin
   for attributeIndex := 0 to Pred(ofNode.AttributeNodes.Count) do begin
      attribute := ofNode.AttributeNodes.Get(attributeIndex);
      WriteLn(attribute.NodeName, ' = ', attribute.NodeValue);
   end;
end;
Nur musst du dann auch auf Groß- und Kleinschreibung achten! Du hattest "Jump" klein geschrieben.
  Mit Zitat antworten Zitat