![]() |
Attribut auslesen..
Hallo, ich versuche hier verzweifelt ein Attribut auszulesen und es will und will nich klappen -.-
xml:
XML-Code:
(gekürtzt)
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <yweather:condition text="Fair" code="33" temp="7" date="Tue, 01 May 2007 10:20 pm CEST" /> </channel> </rss> code:
Delphi-Quellcode:
aber es kommt nur immer sowas wie kann nicht "null" in "string" konvertieren :(
xmldoc.LoadFromXML(weather);
xmldoc.Active:=true; value:=xmldoc.DocumentElement.ChildNodes['channel'].ChildNodes['yweather:condition'].GetAttributeNS('temp',''); was ist denn da nur los? |
Re: Attribut auslesen..
Attribute liest man wie Knoten aus, nur mit einem @ davor.
|
Re: Attribut auslesen..
wie lese ich einen Knoten aus?
ChildNodes['bla'].Text? und wohin soll das @? |
Re: Attribut auslesen..
Vor das bla: '@bla'.
|
Re: Attribut auslesen..
hmmm...also ich blick da echt überhaupt nicht durch!
jetzt kommt die Meldung Project raised exception class EOleException with message 'This name may not contain the ':' character: yweather-->:<--@temp'. bei der Zeile value:=Form1.xmldoc.DocumentElement.ChildNodes['channel'].ChildNodes['yweather:condition'].ChildNodes['@temp'].Text; und der rss Datei ![]() ( <yweather:condition text="Fair" code="33" temp="7" date="Tue, 01 May 2007 10:20 pm CEST" /> ) |
Re: Attribut auslesen..
Die Eigenschaft ChildNodes sieht mir so aus, als wenn es eine Liste wäre. Also müsste da wohl irgendwie ein Zähler hin:
Delphi-Quellcode:
Oder so ähnlich. Aber dazu gibt es hier im Forum auch schon einen Thread. Benutz einfach mal die Suche.
value:=Form1.xmldoc.DocumentElement.ChildNodes[i].Node['@temp'].Text;
|
Re: Attribut auslesen..
na mensch, nen bisschen rumprobiert hab ich auch schon -.-
ChildNodes funktioniert, sofern ich nur den Wert dieses Knotens will und nicht den WErt von nem Attribut :( value:=Form1.xmldoc.DocumentElement.ChildNodes['channel'].ChildNodes['description'].Text funktioniert z.b. wunderbar und mit der Suche hab ich mich mittlerweile auch schon bestimmt ne stunde beschäftigt :wall: |
Re: Attribut auslesen..
Hallo,
so geht es:
Delphi-Quellcode:
Grüße vom marabu
var
xnChannel, xnCondition: IXMLNode; begin xnChannel := xmldoc.DocumentElement.ChildNodes['channel']; xnCondition := xnChannel.ChildNodes['condition']; ShowMessage(VarToStr(xnCondition.Attributes['temp'])); end; |
Re: Attribut auslesen..
hm...danke das ihr euch alle solche Mühe macht, aber es geht trotzdem nicht :wall:
Result bleibt leer... hier mal der Komplette Quelltext, einfach ein TXMLDocument aufs Form geknallt und dann müsste das doch gehen :wall:
Delphi-Quellcode:
function getWeather():string;
var weatherCheck:TidHTTP; weather:string; xnChannel, xnCondition: IXMLNode; begin try weatherCheck := TidHTTP.Create; //http://xml.weather.yahoo.com/forecastrss?p=GMXX1930&u=c weather := weatherCheck.Get('http://xml.weather.yahoo.com/forecastrss?p=GMXX1930&u=c'); Form1.xmldoc.LoadFromXML(weather); Form1.xmldoc.Active:=true; xnChannel := Form1.xmldoc.DocumentElement.ChildNodes['channel']; xnCondition := xnChannel.ChildNodes['condition']; result := VarToStr(xnCondition.Attributes['temp']); weatherCheck.Free; except result := 'could not retrieve weather data'; end; end; |
Re: Attribut auslesen..
Hallo,
mein Code-Beispiel war auf dein XML-Fragment aus Beitrag #1 zugeschnitten. Wenn du die Daten aus dem Feed verwendest, dann musst du darauf achten, dass <condition> kein direkter childNode von <channel> ist (rss/channel/item/condition):
Delphi-Quellcode:
Freundliche Grüße
var
xnChannel, xnItem, xnCondition: IXMLNode; begin xnChannel := xmldoc.DocumentElement.ChildNodes['channel']; xnItem := xnChannel.ChildNodes['item']; xnCondition := xnChannel.ChildNodes['condition']; ShowMessage(VarToStr(xnCondition.Attributes['temp'])); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:47 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz