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

如何使用C#获取XML节点的下一个文本?

发布时间:2020-12-16 00:12:46 所属栏目:百科 来源:网络整理
导读:我有以下 XML.鉴于classname,我需要获得相应的colorcode.我怎样才能在C#中实现这一目标? 否则说,我必须到达一个特定的节点,给出它以前节点的文本. 非常感谢你 ?xml version="1.0" encoding="ISO-8859-1" standalone="yes"??xml-stylesheet type='text/xsl'
我有以下 XML.鉴于classname,我需要获得相应的colorcode.我怎样才能在C#中实现这一目标?
否则说,我必须到达一个特定的节点,给出它以前节点的文本.
非常感谢你

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<?xml-stylesheet type='text/xsl' href='template.xslt'?>
<skin name="GHV--bordeaux">
  <color>
    <classname>.depth1</classname>
    <colorcode>#413686</colorcode>
  </color>
  <color>
    <classname>.depth2</classname>
    <colorcode>#8176c6</colorcode>
  </color>...

解决方法

将xml加载到XmlDocument中,然后执行:

document.SelectSingleNode("/skin/color[classname='.depth1']/colorcode").InnerText

(编辑:李大同)

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

    推荐文章
      热点阅读