private XmlReader CreateContextReader(string xml, bool fromCurrentNode)
{
if (xml == null)
{
throw new ArgumentNullException(nameof(xml));
}
// We have to set the namespace context for the reader.
XPathNavigator editor = CreateNavigator();
// scope starts from parent.
XmlNamespaceManager mgr = new XmlNamespaceManager(NameTable);
if (!fromCurrentNode)
{
editor.MoveToParent(); // should always succeed.
}
if (editor.MoveToFirstNamespace(XPathNamespaceScope.All))
{
do
{
mgr.AddNamespace(editor.LocalName, editor.Value);
}
while (editor.MoveToNextNamespace(XPathNamespaceScope.All));
}
// BUGBUG: How can we preserve the whitespace setting
XmlParserContext context = new XmlParserContext(NameTable, mgr, null, XmlSpace.Default);
XmlTextReader reader = new XmlTextReader(xml, XmlNodeType.Element, context);
// BUGBUG: Whitespace handling??
reader.WhitespaceHandling = WhitespaceHandling.Significant;
return reader;
}