2
检索XML节点的最快方法是什么?我有一个应用程序需要替换特定节点的功能,当文档很小时很快,但很快就会变得更大,然后需要几秒钟才能完成替换。这是方法,我只是做了一个暴力比较,在这种情况下真的很糟糕。什么是通过ID检索Xml节点的最快方法
public bool ReplaceWithAppendFile(string IDReplace)
{
XElement UnionElement = (from sons in m_ExtractionXmlFile.Root.DescendantsAndSelf()
where sons.Attribute("ID").Value == IDReplace
select sons).Single();
UnionElement.ReplaceWith(m_AppendXmlFile.Root.Elements());
m_ExtractionXmlFile.Root.Attribute("MaxID").Value =
AppendRoot.Attribute("MaxID").Value;
if (Validate(m_ExtractionXmlFile, ErrorInfo))
{
m_ExtractionXmlFile.Save(SharedViewModel.ExtractionFile);
return true;
}
else
{
m_ExtractionXmlFile = XDocument.Load(SharedViewModel.ExtractionFile);
return false;
}
}
你可以看看XPath,它通常用于这样的目的。 –