您的位置:首页 > 其它

.net操作xml小结————《一》

2010-08-09 16:46 495 查看
XmlDocument docu = new XmlDocument();是xml的文档对象

XmlElement element = docu .DocumentElement;//得到所有的xml元素

XmlNodeList nodeList = element .SelectNodes(“/加工贸易报文/报文体/申报数据/原地转型主要内容”);//根据节点找子节点

//第一个参数:父节点的位置;第二个参数:要找的节点;第三个参数:要修改的数据;第四个参数:找第几个子节点

//position = 0 表示是第一个《原地转型主要内容》节点

public void UpDateData(string parentPath, string tableName, ArrayList data, int position)
{

XmlNodeList nodeList;
XmlElement root = this._xmlDoc.DocumentElement;
nodeList = root.SelectNodes(parentPath + "/" + tableName);//根据节点找子节点

if (position < nodeList.Count )
{
// 循环ArrayList获取指定的数据列
for(int i=0; i< data.Count; i++)
{
DataField currentDataField = null;
// 添加表的列值
DataField dataField = (DataField)data[i];

XmlElement currentNode = null;
// 获取子元素
XmlNodeList childNodeList = nodeList[position].ChildNodes;
for (int j=0; j<childNodeList.Count; j++)
{
currentNode = (XmlElement)childNodeList[j];

if (dataField.Name == currentNode.Name)
{
currentDataField = dataField;
break;
}

}
if (currentDataField != null)
{
if (currentDataField.Value == null)
{
currentNode.RemoveAllAttributes();
currentNode.SetAttribute("xmlns:xsi", Constant.Xmlns_xsi);
currentNode.SetAttribute("xsi:nil", "true");
currentNode.InnerText = "";

}
else
{
currentNode.RemoveAllAttributes();
currentNode.InnerText = currentDataField.Value.ToString();
}

}
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: