-1
夥計們,我可以使用vb.net插入數據庫循環xml信息?如何Vb.net的XML循環
我嘗試一些少數的編解碼器,但循環不工作
<?xml version="1.0" encoding="UTF-8"?>
<ComputerInformations>
<ComputerInformation>
<CompName>TESTUSER</CompName>
<CompModel>OptiPlex 990</CompModel>
<CompDomain>dnsx.local</CompDomain>
<CompSystemType>x64-based PC</CompSystemType>
</ComputerInformation>
<ComputerMemoryInformations>
<ComputerMemoryInformation>
<CompMemBank>BANK 1</CompMemBank>
<CompMemCapacity>2GB</CompMemCapacity>
<CompMemManufacturer>Hynix/Hyundai</CompMemManufacturer>
<CompMemPartNumber>HMT125U7BFR8C-G7</CompMemPartNumber>
<CompMemSerialNumber>1B73E64A</CompMemSerialNumber>
<CompMemSpeed>1067</CompMemSpeed>
<CompMemBank>BANK 2</CompMemBank>
<CompMemCapacity>2GB</CompMemCapacity>
<CompMemManufacturer>Hynix/Hyundai</CompMemManufacturer>
<CompMemPartNumber>HMT125U7BFR8C-G7</CompMemPartNumber>
<CompMemSerialNumber>1BB3E65E</CompMemSerialNumber>
<CompMemSpeed>1067</CompMemSpeed>
</ComputerMemoryInformation>
</ComputerMemoryInformations>
</ComputerInformations>
這是我的vb.net編解碼器,我使用vb.net 2015年:
Function ParseXmltoDatabase(ByVal XmlData As String)
Dim sr As New System.IO.StringReader(XmlData)
Dim reader = System.Xml.XmlReader.Create(sr)
reader.MoveToContent()
Dim inputXml = XDocument.ReadFrom(reader)
Dim XmlDoc = XDocument.Parse(inputXml.ToString)
Dim Xdoc As XmlDocument = New XmlDocument()
Xdoc.LoadXml(XmlDoc.ToString)
For Each node As XmlNode In Xdoc.SelectNodes("/ComputerInformations/ComputerMemoryInformations/ComputerMemoryInformation")
Dim ComputerMemoryInformation As XmlElement = TryCast(node, XmlElement)
Dim CompMemBank As XmlElement = DirectCast(ComputerMemoryInformation.SelectSingleNode("CompMemBank"), XmlElement)
If CompMemBank IsNot Nothing Then
Console.WriteLine("CompMemBank: {0}", CompMemBank.InnerText)
End If
Console.WriteLine()
Next
問題是隻有我得到第一個結果CompMemBank the Each is not working
您的XML格式不正確,我們無法猜測它應該是什麼。修復並再次詢問。 – MrGadget
謝謝正確的XML添加到問題 – Chacaman