我有一個字符串,其中包含一些我想要操作的數據,所以我將它發送到執行此操作的函數。如何將IEnumerable <XElement>轉換爲字符串
我想在函數中操作後返回該字符串。
我設法給是從包含正確的內容,函數返回IEnumerable<XElement>
後,他得到操縱
我試圖從函數返回xmlElements.ToString();
,但它包含了一些奇怪的字符串,而不是實際的字符串,它的自我。
renderedOutput =在XML結構的字符串
var xml = XElement.Parse(renderedOutput);
IEnumerable<XElement> xmlElements = xml.Descendants();
那麼我將它發送到該功能(即改變一些值)
xmlElements = SetAdditionalData(xmlElements, docIDs[i], i, orderID);// This is the place where i want to get a String in XML strcture
這只是功能做什麼的例子:
public IEnumerable<XElement> SetAdditionalData(IEnumerable<XElement> xmlElements, string docID, int i, string orderID)
{
foreach (var el in xmlElements)
{
// set country name from country iso
if (el.Name == "Country")
{
var isoC = el.Value.ToString().Trim();
if (isoC != string.Empty)
{
RegionInfo isoCode = new RegionInfo(isoC);
el.SetValue(isoCode.DisplayName);
}
continue;
}
}
return xmlElements; // tried to return xmlElements.ToSting(), but it didn't returned the right data
}
我試圖做到這一點:
xmlElements將包含操縱後的字符串 - 意思SetAdditionalData()
後設置一些額外的數據
@亨克我期待'XML字符串' –
@亨克,問我提到,我正在尋找'xmlElements.ToSting()'哪些不起作用 –