XML字符串遍历节点后如何赋值更简单,以下代码中赋值语句能简化吗?希望可以不转化成字符串再拆分赋值
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSy...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Test
{
class ReceiveString
{
public XmlToObject ReceiveXmlString(string message)
{
XmlToObject xto = new XmlToObject();
XmlDocument doc = new XmlDocument();
string str="";
doc.LoadXml(message);//加ó载?xml
XmlNodeList nodesList = doc.GetElementsByTagName("MsgHead"); //取?得?节ú点?名?为aREP_CONTENT的?XmlNode集ˉ合?
foreach (XmlNode xxNode in nodesList)
{
XmlNodeList childList = xxNode.ChildNodes; //取?得?REP_CONTENT下?的?子哩节ú点?集ˉ合?
foreach (XmlNode xxNodes in childList)
{
str +=xxNodes.InnerText+"," ;
}
string[] myStings;
myStings = str.Split(',');
xto.MsgID = myStings[0];
xto.MsgV = myStings[1];
xto.MsgSrcID = myStings[2];
xto.MsgType = myStings[3];
xto.MsgBroadCast = myStings[4];
xto.MsgPriority = myStings[5];
xto.MsgChannelNO = myStings[6];
xto.MsgSendTime = myStings[7];
xto.MsgRecvTime = myStings[8];
}
return xto;
}
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Test
{
class ReceiveString
{
public XmlToObject ReceiveXmlString(string message)
{
XmlToObject xto = new XmlToObject();
XmlDocument doc = new XmlDocument();
string str="";
doc.LoadXml(message);//加ó载?xml
XmlNodeList nodesList = doc.GetElementsByTagName("MsgHead"); //取?得?节ú点?名?为aREP_CONTENT的?XmlNode集ˉ合?
foreach (XmlNode xxNode in nodesList)
{
XmlNodeList childList = xxNode.ChildNodes; //取?得?REP_CONTENT下?的?子哩节ú点?集ˉ合?
foreach (XmlNode xxNodes in childList)
{
str +=xxNodes.InnerText+"," ;
}
string[] myStings;
myStings = str.Split(',');
xto.MsgID = myStings[0];
xto.MsgV = myStings[1];
xto.MsgSrcID = myStings[2];
xto.MsgType = myStings[3];
xto.MsgBroadCast = myStings[4];
xto.MsgPriority = myStings[5];
xto.MsgChannelNO = myStings[6];
xto.MsgSendTime = myStings[7];
xto.MsgRecvTime = myStings[8];
}
return xto;
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询