PDA

View Full Version : مبتدی: خواندن اطلاعات درون فایل xml



vrbahrami
سه شنبه 15 مهر 1399, 20:27 عصر
سلام
یک فایل xml دارم که اتریبیوت feels_like سه بار تکرار شده



<forecast>

<time from="2020-10-05T15:00:00" to="2020-10-05T18:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation probability="0.45"/>
<windDirection deg="37" code="NE" name="NorthEast"/>
<windSpeed mps="0.58" unit="m/s" name="Calm"/>
<temperature unit="celsius" value="17.2" min="17.2" max="18.46"/>
<feels_like value="15.9" unit="celsius"/>
<pressure unit="hPa" value="1021"/>
<humidity value="48" unit="%"/>
<clouds value="broken clouds" all="57" unit="%"/>
<visibility value="10000"/>
</time>

<time from="2020-10-05T18:00:00" to="2020-10-05T21:00:00">
<symbol number="500" name="light rain" var="10n"/>
<precipitation probability="0.36" unit="3h" value="0.2" type="rain"/>
<windDirection deg="45" code="NE" name="NorthEast"/>
<windSpeed mps="2" unit="m/s" name="Light breeze"/>
<temperature unit="celsius" value="17.29" min="17.29" max="17.64"/>
<feels_like value="14.75" unit="celsius"/>
<pressure unit="hPa" value="1020"/>
<humidity value="44" unit="%"/>
<clouds value="broken clouds" all="60" unit="%"/>
<visibility value="10000"/>
</time>

<time from="2020-10-05T21:00:00" to="2020-10-06T00:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation probability="0.08"/>
<windDirection deg="109" code="ESE" name="East-southeast"/>
<windSpeed mps="0.9" unit="m/s" name="Calm"/>
<temperature unit="celsius" value="16.72" min="16.72" max="16.77"/>
<feels_like value="14.72" unit="celsius"/>
<pressure unit="hPa" value="1020"/>
<humidity value="42" unit="%"/>
<clouds value="broken clouds" all="58" unit="%"/>
<visibility value="10000"/>
</time>

</forecast>

با قطعه کدی که دارم فقط مقدار value و unit اولی رو میتونم بخوانم.

Dim e1 As String
Dim m_xmld As XmlDocument = New XmlDocument
m_xmld.Load("forecast.xml")
Dim loc_node As XmlNode = m_xmld.SelectSingleNode("forecast/time/feels_like")
e1 = (loc_node.Attributes("value").Value)
MessageBox.Show(e1)

چطور میتونم مقدار feels_like دومی رو فقط بخونم و نه بیشتر؟ :متفکر:

the king
سه شنبه 15 مهر 1399, 20:49 عصر
سلام
یک فایل xml دارم که اتریبیوت feels_like سه بار تکرار شده



<forecast>

<time from="2020-10-05T15:00:00" to="2020-10-05T18:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation probability="0.45"/>
<windDirection deg="37" code="NE" name="NorthEast"/>
<windSpeed mps="0.58" unit="m/s" name="Calm"/>
<temperature unit="celsius" value="17.2" min="17.2" max="18.46"/>
<feels_like value="15.9" unit="celsius"/>
<pressure unit="hPa" value="1021"/>
<humidity value="48" unit="%"/>
<clouds value="broken clouds" all="57" unit="%"/>
<visibility value="10000"/>
</time>

<time from="2020-10-05T18:00:00" to="2020-10-05T21:00:00">
<symbol number="500" name="light rain" var="10n"/>
<precipitation probability="0.36" unit="3h" value="0.2" type="rain"/>
<windDirection deg="45" code="NE" name="NorthEast"/>
<windSpeed mps="2" unit="m/s" name="Light breeze"/>
<temperature unit="celsius" value="17.29" min="17.29" max="17.64"/>
<feels_like value="14.75" unit="celsius"/>
<pressure unit="hPa" value="1020"/>
<humidity value="44" unit="%"/>
<clouds value="broken clouds" all="60" unit="%"/>
<visibility value="10000"/>
</time>

<time from="2020-10-05T21:00:00" to="2020-10-06T00:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation probability="0.08"/>
<windDirection deg="109" code="ESE" name="East-southeast"/>
<windSpeed mps="0.9" unit="m/s" name="Calm"/>
<temperature unit="celsius" value="16.72" min="16.72" max="16.77"/>
<feels_like value="14.72" unit="celsius"/>
<pressure unit="hPa" value="1020"/>
<humidity value="42" unit="%"/>
<clouds value="broken clouds" all="58" unit="%"/>
<visibility value="10000"/>
</time>

</forecast>

با قطعه کدی که دارم فقط مقدار value و unit اولی رو میتونم بخوانم.

Dim e1 As String
Dim m_xmld As XmlDocument = New XmlDocument
m_xmld.Load("forecast.xml")
Dim loc_node As XmlNode = m_xmld.SelectSingleNode("forecast/time/feels_like")
e1 = (loc_node.Attributes("value").Value)
MessageBox.Show(e1)

چطور میتونم مقدار feels_like دومی رو فقط بخونم و نه بیشتر؟ :متفکر:
بهتره که مجموعه اش رو بخونید تا از هر کدوم که مورد نیازتونه بر اساس شماره اندیس اش استفاده کنید.

Dim e2 As String
Dim m_xmld As XmlDocument = New XmlDocument
m_xmld.Load("forecast.xml")
Dim loc_nodes As XmlNodeList = m_xmld.SelectNodes("forecast/time/feels_like")
e2 = (loc_nodes(1).Attributes("value").Value)
MessageBox.Show(e2)

vrbahrami
سه شنبه 15 مهر 1399, 22:55 عصر
دستت درد نکنه، خیر ببینی برادر :تشویق: