有人能幫助我如何讀取xml中的值與他的格式?以下是xml樣本。我需要得到以下內容:VB.net閱讀XML
>id = 4ebc-9c89
>employeeidnumber = 12345
>name = Smith, John
>weekday = 31/10/2016
>reason = VL
>weekday = 1/11/2016
>reason = VL
>id = 35bc-9c89
>employeeidnumber = 54321
>name = Smith, Jane
>weekday = 1/11/2016
>reason = VL*
如果員工申請兩個或更多假期,程序應該獲得他/她的所有葉子。
<employeeleaverequest>
<leaverequest>
<id>4ebc-9c89</id>
<employeeidnumber>12345</employeeidnumber>
<name>Smith, John</name>
<company name="ABC Company">42b8</company>
<position name="08">-d00077504</position>
<dayleaverequest>
<weekday date="31/10/2016">2</weekday>
<segments>
<segment>
<id>ae2f2c</id>
<hours>8</hours>
<reason name="Vacation Leave">VL</reason>
<status>1</status>
</segment>
</segments>
</dayleaverequest>
<dayleaverequest>
<weekday date="1/11/2016">3</weekday>
<segments>
<segment>
<id>96898</id>
<hours>8</hours>
<reason name="Vacation Leave">VL</reason>
<status>1</status>
</segment>
</segments>
</dayleaverequest>
</leaverequest>
<leaverequest>
<id>35bc-9c89</id>
<employeeidnumber>54321</employeeidnumber>
<name>Smith, Jane</name>
<company name="ABC Company">42b8</company>
<position name="08">-d00077504</position>
<dayleaverequest>
<weekday date="1/11/2016">2</weekday>
<segments>
<segment>
<id>ae333c</id>
<hours>8</hours>
<reason name="Vacation Leave">VL</reason>
<status>1</status>
</segment>
</segments>
</dayleaverequest>
</leaverequest>
</employeeleaverequest>
這是我的代碼到目前爲止。
For Each Node As XmlElement In nodelist
strId = Node("id").InnerText
strNumber = Node("employeeidnumber").InnerText
strName = Node("name").InnerText
Dim sLeaveDay As XmlNode = >Node.SelectSingleNode("dayleaverequest")
If strLeaveDay IsNot Nothing Then
strLeaveDay = >sLeaveDay("weekday").Attributes.ItemOf("date").InnerText
End If
Dim sSegments As XmlNode = >Node.SelectSingleNode>("dayleaverequest/segments/segment")
If sSegments IsNot Nothing Then
strReason = sSegments("reason").InnerText
End If
MessageBox.Show(strId & "|" & strNumber & "|" & strName & >"|" & strLeaveDay & "|" & strReason)
Next
您應該添加什麼是當前代碼的問題,一個錯誤(哪個消息),一個意外的行爲(哪一個)。也就是說,如果代碼完全**,如下所示,我懷疑那些散佈在代碼中的字符散佈在問題中 – Sehnsucht
上面的代碼只是爲每個人選擇第一個假。我想循環dayleaverequest,以便它會輸出多個假如果有多個假期。我不知道那些來自哪裏。我的代碼沒有這些字符。 – Marlofs