C# 将XML文件里的内容提取出来 放到一个字符串数组 求代码
内容为:<?xmlversion="1.0"encoding="UTF-8"?><!--createdbyTOMOVILLH.GYURI--><STATIONNAME="...
内容为:
<?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【】 求代码 展开
<?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【】 求代码 展开
1个回答
展开全部
// 得到DATA节点, xmlDoc为xml文件
XmlNode inputNode = xmlDoc.SelectSingleNode("STATION/DATA");
// 添加到数组data中
string[] data = inputNode.InnerText.Split(';');
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;
用文件位置的话,也是先读取文件中的流,然后转成字符串,同样的道理
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询