public static XQueryNodeIterator QueryNodes(this OpenXmlPart part, OpenXmlElement contextNode, string xquery, XmlNamespaceManager nsmgr) { NameTable nameTable = new NameTable(); OpenXmlDocument doc = new OpenXmlDocument(part, nameTable); OpenXmlNavigator node = new OpenXmlNavigator(new ElementAdapter(contextNode, new RootAdapter(doc.Part.RootElement, doc))); OpenXmlQueryCommand command = new OpenXmlQueryCommand(nameTable); if (nsmgr != null) command.Context.CopyNamespaces(nsmgr); command.ContextItem = node; command.CommandText = xquery; return command.Execute().Preload(); // Load all nodes for preventing to close container before finish query }
public RootAdapter(OpenXmlElement elem, OpenXmlDocument doc) : base(elem) { _doc = doc; }