먼저 XML이 분류됩니다 내 xml 파일
Imports System.Xml
Imports System.IO
Partial Class test2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xmlFileNamae As String = "Vancouver.xml"
Dim xmlFilePath As String = ConfigurationManager.AppSettings("XMLFolder") & xmlFileNamae
If File.Exists(xmlFilePath) Then
Dim docXML As XmlDocument = New XmlDocument
docXML.Load(xmlFilePath)
Dim ID As String = "1"
Dim node As XmlNode = docXML.SelectSingleNode("/Orders/Order[@ID='" & ID & "']/Date")
node.InnerText = Date.Now
node = docXML.SelectSingleNode("/Orders/Order[@ID='" & ID & "']/Country")
node.InnerText = "Vancouver"
docXML.Save(xmlFilePath)
End If
End Sub
End Class
있습니다 : 사전
감사이 내 VB 코드 그것은 틀렸다.
두 번째로 XPath가 좋지 않습니다.
"깨끗한"코드가있는 두 XPath가 있습니다.
Dim XmlDoc As New XmlDocument
Dim Node As XmlNode
XmlDoc.Load(//Your path)
//This will give you the date of the first order item in orders
//where the ID attribute equals 1.
Node = XmlDoc.SelectSingleNode("/Orders/order[@ID="1"]/Date")
//Do somehintg
//This will give you the country of the first order item in orders
//where the ID attribute equals 1.
Node=XmlDoc.SelectSingleNode("/Orders/order[@ID="1"]/Country")
//Do something else.
어떤 줄 올리기 오류가 있습니까? – Fabio
오류가 발생한 행을 정교하게 설명 할 수 있습니까? 첫 번째 모습에서, 나는'xmlFilePath'가 잘못 작성된 '& xmlFileNamae'가 아니라고 생각합니다.'.Load()'가 오류를 발생시킵니다. –
@Nadeem_MK,이 줄에 Dim 노드로 XmlNode = docXML.SelectSingleNode ("/ Files/File [@ ID = '"& ID & "']/Date")를 던집니다. 노드가 없습니다. 노드가 없으므로 – user819774