.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();
}
}
}
}
}
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();
}
}
}
}
}
相关文章推荐
- .net操作xml小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- java使用dom4j和XPath解析XML与.net 操作XML小结
- .net操作xml小结
- .net 操作XML小结
- .net操作xml小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- .net 操作XML小结
- 【转】.net 操作XML小结 --Beyond the dream——飛雪飄寒
- .net 操作XML小结
- .net 操作XML小结
- .net操作xml小结————《二》