c# - Only get the XML node with the Specific value -
im doing weather application works encountered problem. xml seems like:
<city> <city_code>de0011259</city_code> <name>wegberg</name> <url>deutschland/wegberg/de0011259.html</url> <post_code>41844</post_code> <forecast> <date value="2014-12-01"> <w>2</w> <tx>4</tx> <pc>30</pc> <time value="06:00"> <w>2</w> <tx>3</tx> <pc>30</pc> <tn>2</tn> <ws>11</ws> <w_txt>wolkig</w_txt> </time> <time value="11:00"> <w>2</w> <tx>4</tx> <pc>20</pc> <tn>3</tn> <ws>12</ws> <w_txt>wolkig</w_txt> </time> <time value="17:00"> <w>2</w> <tx>4</tx> <pc>20</pc> <tn>1</tn> <ws>9</ws> <w_txt>wolkig</w_txt> </time> <time value="23:00"> <w>2</w> <tx>1</tx> <pc>30</pc> <tn>1</tn> <ws>7</ws> <w_txt>wolkig</w_txt> </time> <tn>1</tn> <ws>10</ws> <w_txt>wolkig</w_txt> </date> </forecast> </city>
sorry if english bad^^ question how data other time´s problem data 6:00 , don´t know how data 17:00 or 23:00
my code getting weather:
string xml; using (var webclient = new webclient()) { xml = webclient.downloadstring(url); } xdocument doc = xdocument.parse(xml); string wind = doc.xpathselectelement("/city/forecast/date/time/ws").value + " km/h";
my problem data 6:00 , don´t know how data 17:00 or 23:00
seems should have condition in xpath, ex.,
string wind = doc.xpathselectelement("/city/forecast/date/time[@value='17:00']/ws") .value + " km/h";
(see [@value='17:00']
)
if want values can use xpathselectelement**s**
said in comments.
Comments
Post a Comment