I have an xml like mentioned below:
<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>
I have to change the node value 'Value' from C:\Users\laitkor\Downloads\BulkTest826.mp4
to BulkTest826.mp4
.
I have tried changing the value by using:
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;
}
But the value of nodes I am getting in XML format does not have the updated Value for 'Value' node at line mentioned with comment 'issue here'
I'm supposing that you want to this more than once for different files. I used to replace the
C:\Users\laitkor\Downloads\
, if the location can be different you can find index of last\
andsubstring
till this index.Use XElement from System.Linq.Xml namespace. Much more intuitive XML parsing.
You can do like this:
Problem is that you are trying to get from node /Attributes/Attribute node /Attributes/Attribute/Value
try this