zoukankan      html  css  js  c++  java
  • c# 读取xml 某个节点值

    一、xml格式如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <Freight>
    <freight Area="河南" ExpreName="圆通">
    <FreYkg>1000</FreYkg>
    <FreYkgPrice>800</FreYkgPrice>
    <FreAkg>2000</FreAkg>
    <FreAkgPrice>200</FreAkgPrice>
    </freight>
    <freight Area="河北" ExpreName="圆通">
    <FreYkg>1000</FreYkg>
    <FreYkgPrice>800</FreYkgPrice>
    <FreAkg>2000</FreAkg>
    <FreAkgPrice>200</FreAkgPrice>
    </freight>
    </Freight>

    想要获取的内容是:Area="河北"  下某节点值,应该怎么读取

    XmlDocument doc = new XmlDocument();
    string path = Server.MapPath("../Xml/EMS.xml");
    doc.Load(path);
    XmlNode node = doc.SelectSingleNode("Freight/freight[@Area='河北']|Freight/freight[@ExpreName='圆通']");/*查询的条件Area='河北' 或者 ExpreName='圆通'*/

    if(node!=null)

    {

      string basePrice = node.SelectSingleNode("FreYkg").InnerText;

      string price = node.SelectSingleNode("FreYkgPrice").InnerText;

    }

  • 相关阅读:
    DRF JWT认证基础
    Shell简单脚本
    DockerFile案例
    Shell基础知识
    DockerFile基础知识
    tensorflow
    使用cv2将图片分割成相等的部分
    序列化心得
    python正则化表达式
    python--匿名函数(lambda)
  • 原文地址:https://www.cnblogs.com/xiaxiaomo/p/9044730.html
Copyright © 2011-2022 走看看