Vor einiger Zeit fragte ich die Frage, wie aus einem XML-Dokument lesen und den Wert verwenden (siehe C# xdocument read from element and put the value into string)C# Linq alle Elemente in Nachkomme erhalten und teilen Sie den Wert
Nun habe ich folgendes Problem, die Lösung gegeben in den letzten Thread funktioniert, aber nur, wenn ich dies tun:
<root>
<test>
<Copy01>@[email protected]\test1 ,@[email protected]\test2</Copy01>
</test>
</root>
aber ich möchte etwas wie folgt aus:
<root>
<test>
<Copy01>@[email protected]\test1 ,@[email protected]\test2</Copy01>
<Copy02>@[email protected]\test3 ,@[email protected]\test4</Copy02>
</test>
</root
aber mit dem folgenden Code in C#:
var copyitems = doc.Descendants(param[1])
.Select(s =>
{
var splits = s.Value.Split(new string[] { "@[email protected]", "@[email protected]" }, StringSplitOptions.RemoveEmptyEntries); // split the string to separate source and destination.
return new { Source = splits[0].Replace(",", ""), Destination = splits[1].Replace(",", "") };
})
.ToList();
Wert des param [1] ist, "test" in diesem Fall es nimmt nur die erste Kopie (copy01) und nicht die zweiten.
Irgendeine Idee, wie man das repariert?
Nick
Was ist der Wert von 'param [1]' ist? –
Sorry, dieser Wert ist in diesem Fall "test" – Dutchdeveloper