English 中文(简体)
您能否改进这一支气炉到xml方法的绩效?
原标题:Can you improve the performance of this linq-to-xml method?

今天上午我确实需要到其他地方。 因此,我决定在此提出业绩问题。

下面的法典有多种功能,但称之为“洛德”和“拯救儿童”方法。 这似乎远远没有效率。 请有人提供该法典,但装货和储蓄线在休息室外。 我只想提负荷和节省一次。

章 次 页 次

 public void RemoveNodes(IList<String> removeItems)

    {

        foreach (String removeItem in removeItems)

        {

            XDocument document = XDocument.Load(fullFilePath);

            var results = from item in document.Descendants(elementName)

                          let attr = item.Attribute(attributeName)

                          where attr != null && attr.Value == removeItem.ToString()

                          select item;

            results.ToList().ForEach(item => item.Remove());

            document.Save(fullFilePath);

        }

    }
最佳回答

您已经给出了答案——只是将LoadSave打电话到路外。 我不清楚,在什么地方,你在执行《公约》方面存在问题。

您可以稍微简单地简单地回答:

XDocument document = XDocument.Load(fullFilePath);
foreach (String removeItem in removeItems)
{
    var results = from item in document.Descendants(elementName)
                  where (string) item.Attribute(attributeName) == removeItem
                  select item;
    results.ToList().ForEach(item => item.Remove());
}
document.Save(fullFilePath);

因此,如果属性参考本身无效,则从<代码>XAttribute改为string收益无效。

甚至不需要用问话表达:

var results = document.Descendants(elementName)
          .Where(item => (string) item.Attribute(attributeName) == removeItem);
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签