繁体   English   中英

如何在 XML 元素中保存多个值?

[英]How to hold more than one values in XML element?

xWaarde.Value 正在覆盖新值并刷新旧值。

如何在 Xelement 中存储多个值。

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);

您还可以添加子元素列表或将所有字符串添加为一个字符串,例如用逗号分隔。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM