首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从xmlNodeList中删除节点

从xmlNodeList中删除节点
EN

Stack Overflow用户
提问于 2015-10-01 10:58:02
回答 1查看 52关注 0票数 0

这是我的密码

代码语言:javascript
复制
    public bool limitOutput()
    {
        double lowerLeftPointX = m_mapControl.CurrentExtent.LowerLeftPoint.X;
        double lowerLeftPointY = m_mapControl.CurrentExtent.LowerLeftPoint.Y;
        double upperRightPointX = m_mapControl.CurrentExtent.UpperRightPoint.X;
        double upperRightPointY = m_mapControl.CurrentExtent.UpperRightPoint.Y;

        for(int i = locationElements.Count - 1; i >= 0; i--)
        {
            if (Double.Parse(locationElements[i]["GEOMETRY_X"].InnerText) < lowerLeftPointX || Double.Parse(locationElements[i]["GEOMETRY_X"].InnerText) > upperRightPointX || Double.Parse(locationElements[i]["GEOMETRY_Y"].InnerText) < lowerLeftPointY || Double.Parse(locationElements[i]["GEOMETRY_Y"].InnerText) > upperRightPointY)
            {
                locationElements[i].ParentNode.RemoveChild(locationElements[i]);
            }
        }

        if (locationElements.Count == 0)
        {
            PearMessageBox.Show(PearMessageBox.mBoxType.simpleNotification, "No results found in specified area");
            return false;
        }
        return true;


    }

我正在尝试删除不在我设置的边界内的所有节点。删除行被执行,但实际上并没有删除,因为当我计算locationElements时,它在执行方法之前仍然是相同的值。

有什么想法吗?代码有什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-01 12:42:32

这个问题是由于RemoveChild()从源XmlDocument中删除了元素,而不是从预先填充的XmlNodeList中删除的。因此,您需要再次执行用于预填充locationElements变量的代码,如下所示:

代码语言:javascript
复制
//assume that GetLocationElements() is a method...
//...containing the same logic you used to populate locationElements variable
var updatedLocationElements = GetLocationElements();
if (updatedLocationElements.Count == 0)
{
    PearMessageBox.Show(PearMessageBox.mBoxType.simpleNotification, "No results found in specified area");
    return false;
}
return true;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32885858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档