【发布时间】:2011-07-05 11:47:04
【问题描述】:
首先,我是XML 和C# 的新手。我需要一些指针来查找和替换 xml 节点值。
我有一个XML 文件,其中包含一组输入参数。我需要在文件中找到一个特定的输入参数(<parameter id="PRP_AsOfDate">),然后更新一个关联的值(<UCDateEndGetString>27/06/2011</UCDateEndGetString>)。
这需要每天完成,所以我需要用标签替换 <UCDateEndGetString> 并替换它。
我尝试了以下代码,但出现非法字符错误。
有人可以帮忙吗?
public string TestRequestDef()
{
string reqtype = "Position";
GetRequestDef getxml = new GetRequestDef();
string xmlcall = getxml.GetXMLRequest(reqtype);
XmlDocument doc = new XmlDocument();
doc.Load(xmlcall);
string newValue = "XXXX";
XmlNode paraNode = doc.SelectSingleNode("parameters/parameter/UCValue/UCPitDateGetString");
paraNode.Attributes[0].Value = newValue;
doc.Save(xmlcall);
return xmlcall;
我正在使用.Net 4.0 和C#。
这是我的一些 xml 文件:
<parameters>
<parameter id="PRP_AsOfDate">
<deoId/>
<groupBy>false</groupBy>
<dateControlVisible>true</dateControlVisible>
<pitControlVisible>true</pitControlVisible>
<excludeFromOutput>false</excludeFromOutput>
<multiCurrencyRequired>false</multiCurrencyRequired>
<label>As Of Date</label>
<style type="Date">
<maxSelect>0</maxSelect>
<minSelect>0</minSelect>
<level/>
<content/>
<fieldTypes/>
<dataObjectType>Date</dataObjectType>
<filter/>
<value/>
<formatString/>
</style>
<formatString/>
<validations/>
<UCValue>
<UCComposites/>
<UCIdGetString/>
<UCNameGetString/>
<UCDateDays>0</UCDateDays>
<UCDateStartGetString>01/01/1900</UCDateStartGetString>
<UCDateEndGetString>27/06/2011</UCDateEndGetString>
<UCPitDateGetString>26/06/2011 00:00:00</UCPitDateGetString>
<UCPitDatePreviousGetString>26/06/2011 00:00:00</UCPitDatePreviousGetString>
<UCPitChecked>True</UCPitChecked>
<UCDateOptionGetString>SPECIFIC</UCDateOptionGetString>
<UCDefaultValueGetString>True|SPECIFIC|27/06/2011|</UCDefaultValueGetString>
<UCValueGetString>True|SPECIFIC|27/06/2011|</UCValueGetString>
</UCValue>
</parameter>
【问题讨论】: