加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何确定XmlNode是否具有特定属性?

发布时间:2020-12-17 07:12:14 所属栏目:百科 来源:网络整理
导读:我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手. Sub InsertNode(ByVal doc As XmlDocument) Dim City As XmlNode = doc.DocumentElement Dim Location As XmlElement = doc.CreateEle
我想在sub中放置一个if条件,告诉它在属性TEST =“test.doc”的xml节点STORE不存在时运行.任何建议都会很棒.我是vb的新手.

Sub InsertNode(ByVal doc As XmlDocument)   
    Dim City As XmlNode = doc.DocumentElement

    Dim Location As XmlElement = doc.CreateElement("store")
    Location.SetAttribute("test","test.doc")

    Dim books As XmlElement = doc.CreateElement("books")
    books.InnerXml = "New Words"
    Location.AppendChild(books)

    City.AppendChild(store)
End Sub 'InsertNode

XML文件的示例

<city>
    <store test="test.doc">
        <books>
        "New Words" 
        </books>
    </store>
</city>

解决方法

尝试类似的东西:

If Not doc.SelectSingleNode("//store[@test='test.doc']") Is Nothing Then
    Exit Sub
End If

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读