如何在vb.net中获取xml中的属性值 [英] how to get attribute value in xml in vb.net
本文介绍了如何在vb.net中获取xml中的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我有一个xml文件
hi i have a xml file
<?xml version="1.0"?>
<Root>
<FileName Name="Logdata">
<Id>720738147</Id>
<FileName>Logdata</FileName>
<FilePath>d:\manohar\Logdata.xml</FilePath>
<Description>fasdf</Description>
</FileName>
<FileName FIleName="RootProcess">
<Id>720738147</Id>
<FileName>RootProcess</FileName>
<FilePath>RootProcess</FilePath>
<Description>fsad fsadf</Description>
</FileName>
<FileName FIleName="PlantProcess">
<Id>789088212</Id>
<FileName>fsad</FileName>
<FilePath>fsad</FilePath>
<Description>fas dsafd</Description>
</FileName>
</Root>
和我的代码是
i想得到name =LogData的属性
但是没有得到
and my code is
i want to get the attribute of name ="LogData"
but not getting
If (IO.File.Exists(Server.MapPath("~/App_Data/XMLFile.xml"))) Then
Dim xd As New XmlDocument()
xd.Load(Server.MapPath("~/App_Data/XMLFile.xml"))
' Find the node where the Person's attribute ID is 1 using its XPath.
Dim nod As XmlNode = xd.SelectSingleNode("/Root/FileName[@Name='LogData']")
If nod IsNot Nothing Then
Dim node As XmlNode = xd.CreateNode(XmlNodeType.Element, "FileName", Nothing)
' doc.DocumentElement.SetAttribute("FileName", "" & dpFiles.SelectedItem.Text & "")
Dim xkey As XmlAttribute = xd.CreateAttribute("FIleName")
xkey.Value = dpFiles.SelectedItem.Text
node.Attributes.Append(xkey)
'create FileName
Dim nodeId As XmlNode = xd.CreateElement("Id")
nodeId.InnerText = lblRandomNumber.Text
'create FileName
Dim nodeFileName As XmlNode = xd.CreateElement("FileName")
nodeFileName.InnerText = txtFileName.Text
'create FilePath
Dim nodeFilePath As XmlNode = xd.CreateElement("FilePath")
nodeFilePath.InnerText = txtFileName.Text
'create FileDesc
Dim nodeFileDesc As XmlNode = xd.CreateElement("Description")
nodeFileDesc.InnerText = txtDesc.Text
'add to parent node
'node.AppendChild(nodeTitle)
node.AppendChild(nodeId)
node.AppendChild(nodeFileName)
node.AppendChild(nodeFilePath)
node.AppendChild(nodeFileDesc)
'add to elements collection
xd.DocumentElement.AppendChild(node)
Else
MsgBox("No node")
End If
' Save the Xml.
xd.Save(Server.MapPath("~/App_Data/XMLFile.xml"))
End If
可以任何帮助关于这个问题
can any one help regarding this issue
推荐答案
在XML中你有Logdata,在代码中你正在搜索LogData(D caps)。 XML是大小写敏感,使其成为同样的情况。
In XML you have Logdata and in code you are searching for LogData (D caps). XML is case sensitve make it same case.
这篇关于如何在vb.net中获取xml中的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文