C# 将XML文件里的内容提取出来 放到一个字符串数组 求代码

内容为:
<?xml version="1.0" encoding="UTF-8"?>
<!-- created by TOMOVILL H.GYURI -->
<STATION NAME="AF90 AGW MONTAGE LINE1">

<NUMBEROFMFU>50</NUMBEROFMFU><DATA>+0.1640000E+00; +0.1640000E+00; +0.1640000E+00; +0.1630000E+00; +0.1639999E+00; +0.1620001E+00; +0.1639999E+00; +0.1639999E+00; +0.1630000E+00; +0.1639999E+00; +0.1630000E+00; +0.1640000E+00; +0.1640000E+00; +0.1630000E+00; +0.1619999E+00; +0.1630000E+00; +0.1640000E+00; +0.1640000E+00; +0.1630000E+00; +0.1630000E+00; +0.1620001E+00; +0.1640000E+00; +0.1639999E+00; +0.1640000E+00; +0.1630000E+00; +0.1620001E+00; +0.1619999E+00; +0.1630000E+00; +0.1630000E+00; +0.1630000E+00; +0.1630000E+00; +0.1640000E+00; +0.1630000E+00; +0.1630001E+00; +0.1640000E+00; +0.1640000E+00; +0.1630000E+00; +0.1640000E+00; +0.1640000E+00; +0.1639999E+00; +0.1630001E+00; +0.1640000E+00; +0.1630001E+00; +0.1619999E+00; +0.1630000E+00; +0.1630000E+00; +0.1640000E+00; +0.1640000E+00; +0.1630000E+00; +0.1630000E+00; </DATA></STATION>
提取如+0.1640000E+00格式的50组数据 放到字符串数组里data【】 求代码

// 得到DATA节点, xmlDoc为xml文件
XmlNode inputNode = xmlDoc.SelectSingleNode("STATION/DATA");
// 添加到数组data中
string[] data = inputNode.InnerText.Split(';');追问

谢谢你 命名空间需要加个using system.xml;就好了 可是xmlDoc需要前面怎么定义啊,比如文件位置为“E:\\123.xml"

追答

如果是做接口,可以用字符串变量,比如
string xmlStr = "";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlStr.Trim());
return xmlDocument;
用文件位置的话,也是先读取文件中的流,然后转成字符串,同样的道理

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答