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

vb.net中用Xpath遍历子节点的问题

发布时间:2020-12-17 08:11:09 所属栏目:百科 来源:网络整理
导读:xml文档的一部分: affiliation OID="" CNY="" TYPE="ORG" orgDivDepartment of Molecular Neuroscience,UCL Institute of Neurology/orgDiv label type="remove" bsType="remove",/label addresscityLondon/citylabel type="remove" bsType="remove",/label

xml文档的一部分:

<affiliation OID="" CNY="" TYPE="ORG">

<orgDiv>Department of Molecular Neuroscience,UCL Institute of Neurology</orgDiv>

<label type="remove" bsType="remove">,</label>

<address><city>London</city><label type="remove" bsType="remove">,</label><country>UK</country></address>

aaaaaaaaaaaaa

</affiliation>

当使用xmlNodeList是,其中是包含文本节点的,即“affiliation”的子节点有5个“aaaaaaaaaaaaa”也算是一个节点,

但是xmlElement就只能是有尖括号的如<orgDiv>

进行遍历的时候

dim ele as xml.xmlElement

For Each ele In affiliationElement.ChildNodes
If ele IsNot Nothing Then
strAffInnerText = strAffInnerText & ele.InnerText
affiliationElement.RemoveChild(ele)
End If
Next

会出错:没有进行循环,因为有 affiliationElement.RemoveChild(ele)这句话,删掉就可以了,原因还不是很清楚???!!!

若不删除ffiliationElement.RemoveChild(ele)这句话,需在循环前面重新选取nodeList,如下:

dim eleNodeLst as xml.xmlNodeList

eleNodeLst =affiliactionEleMent.selectNodes("./*")


但是这样的eleNodeLst 不包含文本节点!

(编辑:李大同)

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

    推荐文章
      热点阅读