C# 如何在XML元素中保存多个值?
值被新值覆盖,并刷新旧值 如何在Xelement中存储多个值C# 如何在XML元素中保存多个值?,c#,C#,值被新值覆盖,并刷新旧值 如何在Xelement中存储多个值 private XElement[] AddCoordinatenList(XElement childElements) { XmlNode xmlCoordinatenNode = Utility.GetMappingValues(Constants.BMCoordinaten, ConnectionType.BM); XmlNode xWaardeNode = Utility.GetMapping
private XElement[] AddCoordinatenList(XElement childElements)
{
XmlNode xmlCoordinatenNode = Utility.GetMappingValues(Constants.BMCoordinaten, ConnectionType.BM);
XmlNode xWaardeNode = Utility.GetMappingValues(Constants.BMXwaarde, ConnectionType.BM);
XmlNode yWaardeNode = Utility.GetMappingValues(Constants.BMYwaarde, ConnectionType.BM);
XmlNode CoordinateX = Utility.GetMappingValues(Constants.XCoordinate, ConnectionType.BM);
XmlNode CoordinateY = Utility.GetMappingValues(Constants.YCoordinate, ConnectionType.BM);
var coordinatenList = from document in childElements.DescendantsAndSelf() where document.Name.LocalName == xmlCoordinatenNode.Name select document;
List<XElement> xcoordinatenList = new List<XElement>();
XElement xWaarde = new XElement(CoordinateX.Name);
XElement yWaarde = new XElement(CoordinateY.Name);
if (coordinatenList.Count() > 0)
{
foreach (XElement element in coordinatenList.Descendants())
{
if (element.Name.LocalName == xWaardeNode.Name)
{
xWaarde.Value = element.Value;
}
if (element.Name.LocalName == yWaardeNode.Name)
{
yWaarde.Value = element.Value;
}
}
}
return xcoordinatenList.ToArray();
}
这是不可能的。使用属性:
XAttribute attribute = new XAttribute("name1", <value>);
element.Add(attribute);
attribute = new XAttribute("name2", <value>);
element.Add(attribute);
您还可以添加子元素列表或将所有字符串添加为一个字符串,例如用逗号分隔。Hi,欢迎使用堆栈溢出!看来你的问题有点欠缺。输入代码时,请确保每行前面至少有4个空格。这样,代码将注册为这样的代码。此外,您所问的问题不是很清楚。我的循环运行了4次,其中4个不同的值-->xWaarde.Value和yWaarde.Value超过了这些值。也就是说,最后的第三个和第四个值存储在xWaarde.Value和yWaarde.Value中……而第一个和第二个值正在浮动,我想将所有4个值存储在coordinalEnlist.degenerations中