private void InitFragmentReader(XmlNodeType fragmentType, XmlParserContext parserContext, bool allowXmlDeclFragment)
{
_fragmentParserContext = parserContext;
if (parserContext != null)
{
if (parserContext.NamespaceManager != null)
{
_namespaceManager = parserContext.NamespaceManager;
_xmlContext.defaultNamespace = _namespaceManager.LookupNamespace(string.Empty);
}
else
{
_namespaceManager = new XmlNamespaceManager(_nameTable);
}
_ps.baseUriStr = parserContext.BaseURI;
_ps.baseUri = null;
_xmlContext.xmlLang = parserContext.XmlLang;
_xmlContext.xmlSpace = parserContext.XmlSpace;
}
else
{
_namespaceManager = new XmlNamespaceManager(_nameTable);
_ps.baseUriStr = string.Empty;
_ps.baseUri = null;
}
_reportedBaseUri = _ps.baseUriStr;
switch (fragmentType)
{
case XmlNodeType.Attribute:
_ps.appendMode = false;
_parsingFunction = ParsingFunction.SwitchToInteractive;
_nextParsingFunction = ParsingFunction.FragmentAttribute;
break;
case XmlNodeType.Element:
Debug.Assert(_parsingFunction == ParsingFunction.SwitchToInteractiveXmlDecl);
_nextParsingFunction = ParsingFunction.DocumentContent;
break;
case XmlNodeType.Document:
Debug.Assert(_parsingFunction == ParsingFunction.SwitchToInteractiveXmlDecl);
Debug.Assert(_nextParsingFunction == ParsingFunction.DocumentContent);
break;
case XmlNodeType.XmlDeclaration:
if (allowXmlDeclFragment)
{
_ps.appendMode = false;
_parsingFunction = ParsingFunction.SwitchToInteractive;
_nextParsingFunction = ParsingFunction.XmlDeclarationFragment;
break;
}
else
{
goto default;
}
default:
Throw(SR.Xml_PartialContentNodeTypeNotSupportedEx, fragmentType.ToString());
return;
}
_fragmentType = fragmentType;
_fragment = true;
}