public override XmlWriter ReplaceRange(XPathNavigator lastSiblingToReplace) {
DocumentXPathNavigator that = lastSiblingToReplace as DocumentXPathNavigator;
if (that == null) {
if (lastSiblingToReplace == null) {
throw new ArgumentNullException("lastSiblingToReplace");
}
else {
throw new NotSupportedException();
}
}
this.CalibrateText();
that.CalibrateText();
XmlNode node = this.source;
XmlNode end = that.source;
if (node == end) {
switch (node.NodeType) {
case XmlNodeType.Attribute:
case XmlNodeType.Document:
case XmlNodeType.DocumentFragment:
throw new InvalidOperationException(Res.GetString(Res.Xpn_BadPosition));
case XmlNodeType.Text:
case XmlNodeType.CDATA:
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Whitespace:
end = that.TextEnd(end);
break;
default:
break;
}
}
else {
if (end.IsText) {
end = that.TextEnd(end);
}
if (!IsFollowingSibling(node, end)) {
throw new InvalidOperationException(Res.GetString(Res.Xpn_BadPosition));
}
}
DocumentXmlWriter writer = new DocumentXmlWriter(DocumentXmlWriterType.ReplaceToFollowingSibling, node, document);
writer.NamespaceManager = GetNamespaceManager(node.ParentNode, document);
writer.Navigator = this;
writer.EndNode = end;
return new XmlWellFormedWriter(writer, writer.Settings);
}