【发布时间】:2014-12-01 10:15:46
【问题描述】:
我有一个如下所述的 xml:
<Attributes>
<Attribute>
<EntryID>0</EntryID>
<ContractID>227860</ContractID>
<FieldID>10882</FieldID>
<GroupID>0</GroupID>
<InstanceID>0</InstanceID>
<Value>C:\Users\laitkor\Downloads\BulkTest826.mp4</Value>
<CreatedBy>615</CreatedBy>
<CreatedOn>12/1/2014 6:51:04 AM</CreatedOn>
<UpdatedBy>615</UpdatedBy>
<UpdatedOn>12/1/2014 6:51:04 AM</UpdatedOn>
</Attribute>
</Attributes>
我必须将节点值“Value”从 C:\Users\laitkor\Downloads\BulkTest826.mp4 更改为 BulkTest826.mp4。
我尝试使用以下方法更改值:
XmlDocument xml = new XmlDocument();
xml.LoadXml(nodes);
bool isMultimedia = false;
XmlNodeList xnList = xml.SelectNodes("/Attributes/Attribute");
foreach (XmlNode xn in xnList)
{
int FieldId = Convert.ToInt32(xn["FieldID"].InnerText);
isMultimedia = true;
if (isMultimedia) {
string MultiMediaFilePath = xn["Value"].InnerText;
createMultimediaFile(FieldId, MultiMediaFilePath, contractID);//todo
string fileName = MultiMediaFilePath.Substring(MultiMediaFilePath.LastIndexOf('\\', MultiMediaFilePath.Length - 1));
fileName = fileName.TrimStart('\\');
xn.SelectSingleNode("/Attributes/Attribute/Value").InnerText = fileName;
}
retval = SiteProvider.ContractBulk.AddBulkContractField(nodes, contractID, groupID, sequenId, 1);//issue here
return retval;
}
但是我以 XML 格式获取的节点的值没有更新的“值”节点的值,在注释“此处发布”提到的行中
【问题讨论】:
-
检查我的解决方案并告诉我这是否是您需要的。