Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Xml / System / Xml / Cache / XPathDocumentIterator.cs / 1 / XPathDocumentIterator.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
using System.Xml;
using System.Xml.XPath;
using System.Diagnostics;
namespace MS.Internal.Xml.Cache {
///
/// Base internal class of all XPathDocument XPathNodeIterator implementations.
///
internal abstract class XPathDocumentBaseIterator : XPathNodeIterator {
protected XPathDocumentNavigator ctxt;
protected int pos;
///
/// Create a new iterator that is initially positioned on the "ctxt" node.
///
protected XPathDocumentBaseIterator(XPathDocumentNavigator ctxt) {
this.ctxt = new XPathDocumentNavigator(ctxt);
}
///
/// Create a new iterator that is a copy of "iter".
///
protected XPathDocumentBaseIterator(XPathDocumentBaseIterator iter) {
this.ctxt = new XPathDocumentNavigator(iter.ctxt);
this.pos = iter.pos;
}
///
/// Return the current navigator.
///
public override XPathNavigator Current {
get { return this.ctxt; }
}
///
/// Return the iterator's current position.
///
public override int CurrentPosition {
get { return this.pos; }
}
}
///
/// Iterate over all element children with a particular QName.
///
internal class XPathDocumentElementChildIterator : XPathDocumentBaseIterator {
private string localName, namespaceUri;
///
/// Create an iterator that ranges over all element children of "parent" having the specified QName.
///
public XPathDocumentElementChildIterator(XPathDocumentNavigator parent, string name, string namespaceURI) : base(parent) {
if (namespaceURI == null) throw new ArgumentNullException("namespaceURI");
this.localName = parent.NameTable.Get(name);
this.namespaceUri = namespaceURI;
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentElementChildIterator(XPathDocumentElementChildIterator iter) : base(iter) {
this.localName = iter.localName;
this.namespaceUri = iter.namespaceUri;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentElementChildIterator(this);
}
///
/// Position the iterator to the next matching child.
///
public override bool MoveNext() {
if (this.pos == 0) {
if (!this.ctxt.MoveToChild(this.localName, this.namespaceUri))
return false;
}
else {
if (!this.ctxt.MoveToNext(this.localName, this.namespaceUri))
return false;
}
this.pos++;
return true;
}
}
///
/// Iterate over all content children with a particular XPathNodeType.
///
internal class XPathDocumentKindChildIterator : XPathDocumentBaseIterator {
private XPathNodeType typ;
///
/// Create an iterator that ranges over all content children of "parent" having the specified XPathNodeType.
///
public XPathDocumentKindChildIterator(XPathDocumentNavigator parent, XPathNodeType typ) : base(parent) {
this.typ = typ;
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentKindChildIterator(XPathDocumentKindChildIterator iter) : base(iter) {
this.typ = iter.typ;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentKindChildIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.pos == 0) {
if (!this.ctxt.MoveToChild(this.typ))
return false;
}
else {
if (!this.ctxt.MoveToNext(this.typ))
return false;
}
this.pos++;
return true;
}
}
///
/// Iterate over all element descendants with a particular QName.
///
internal class XPathDocumentElementDescendantIterator : XPathDocumentBaseIterator {
private XPathDocumentNavigator end;
private string localName, namespaceUri;
private bool matchSelf;
///
/// Create an iterator that ranges over all element descendants of "root" having the specified QName.
///
public XPathDocumentElementDescendantIterator(XPathDocumentNavigator root, string name, string namespaceURI, bool matchSelf) : base(root) {
if (namespaceURI == null) throw new ArgumentNullException("namespaceURI");
this.localName = root.NameTable.Get(name);
this.namespaceUri = namespaceURI;
this.matchSelf = matchSelf;
// Find the next non-descendant node that follows "root" in document order
if (root.NodeType != XPathNodeType.Root) {
this.end = new XPathDocumentNavigator(root);
this.end.MoveToNonDescendant();
}
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentElementDescendantIterator(XPathDocumentElementDescendantIterator iter) : base(iter) {
this.end = iter.end;
this.localName = iter.localName;
this.namespaceUri = iter.namespaceUri;
this.matchSelf = iter.matchSelf;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentElementDescendantIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.matchSelf) {
this.matchSelf = false;
if (this.ctxt.IsElementMatch(this.localName, this.namespaceUri)) {
this.pos++;
return true;
}
}
if (!this.ctxt.MoveToFollowing(this.localName, this.namespaceUri, this.end))
return false;
this.pos++;
return true;
}
}
///
/// Iterate over all content descendants with a particular XPathNodeType.
///
internal class XPathDocumentKindDescendantIterator : XPathDocumentBaseIterator {
private XPathDocumentNavigator end;
private XPathNodeType typ;
private bool matchSelf;
///
/// Create an iterator that ranges over all content descendants of "root" having the specified XPathNodeType.
///
public XPathDocumentKindDescendantIterator(XPathDocumentNavigator root, XPathNodeType typ, bool matchSelf) : base(root) {
this.typ = typ;
this.matchSelf = matchSelf;
// Find the next non-descendant node that follows "root" in document order
if (root.NodeType != XPathNodeType.Root) {
this.end = new XPathDocumentNavigator(root);
this.end.MoveToNonDescendant();
}
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentKindDescendantIterator(XPathDocumentKindDescendantIterator iter) : base(iter) {
this.end = iter.end;
this.typ = iter.typ;
this.matchSelf = iter.matchSelf;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentKindDescendantIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.matchSelf) {
this.matchSelf = false;
if (this.ctxt.IsKindMatch(this.typ)) {
this.pos++;
return true;
}
}
if (!this.ctxt.MoveToFollowing(this.typ, this.end))
return false;
this.pos++;
return true;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
using System.Xml;
using System.Xml.XPath;
using System.Diagnostics;
namespace MS.Internal.Xml.Cache {
///
/// Base internal class of all XPathDocument XPathNodeIterator implementations.
///
internal abstract class XPathDocumentBaseIterator : XPathNodeIterator {
protected XPathDocumentNavigator ctxt;
protected int pos;
///
/// Create a new iterator that is initially positioned on the "ctxt" node.
///
protected XPathDocumentBaseIterator(XPathDocumentNavigator ctxt) {
this.ctxt = new XPathDocumentNavigator(ctxt);
}
///
/// Create a new iterator that is a copy of "iter".
///
protected XPathDocumentBaseIterator(XPathDocumentBaseIterator iter) {
this.ctxt = new XPathDocumentNavigator(iter.ctxt);
this.pos = iter.pos;
}
///
/// Return the current navigator.
///
public override XPathNavigator Current {
get { return this.ctxt; }
}
///
/// Return the iterator's current position.
///
public override int CurrentPosition {
get { return this.pos; }
}
}
///
/// Iterate over all element children with a particular QName.
///
internal class XPathDocumentElementChildIterator : XPathDocumentBaseIterator {
private string localName, namespaceUri;
///
/// Create an iterator that ranges over all element children of "parent" having the specified QName.
///
public XPathDocumentElementChildIterator(XPathDocumentNavigator parent, string name, string namespaceURI) : base(parent) {
if (namespaceURI == null) throw new ArgumentNullException("namespaceURI");
this.localName = parent.NameTable.Get(name);
this.namespaceUri = namespaceURI;
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentElementChildIterator(XPathDocumentElementChildIterator iter) : base(iter) {
this.localName = iter.localName;
this.namespaceUri = iter.namespaceUri;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentElementChildIterator(this);
}
///
/// Position the iterator to the next matching child.
///
public override bool MoveNext() {
if (this.pos == 0) {
if (!this.ctxt.MoveToChild(this.localName, this.namespaceUri))
return false;
}
else {
if (!this.ctxt.MoveToNext(this.localName, this.namespaceUri))
return false;
}
this.pos++;
return true;
}
}
///
/// Iterate over all content children with a particular XPathNodeType.
///
internal class XPathDocumentKindChildIterator : XPathDocumentBaseIterator {
private XPathNodeType typ;
///
/// Create an iterator that ranges over all content children of "parent" having the specified XPathNodeType.
///
public XPathDocumentKindChildIterator(XPathDocumentNavigator parent, XPathNodeType typ) : base(parent) {
this.typ = typ;
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentKindChildIterator(XPathDocumentKindChildIterator iter) : base(iter) {
this.typ = iter.typ;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentKindChildIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.pos == 0) {
if (!this.ctxt.MoveToChild(this.typ))
return false;
}
else {
if (!this.ctxt.MoveToNext(this.typ))
return false;
}
this.pos++;
return true;
}
}
///
/// Iterate over all element descendants with a particular QName.
///
internal class XPathDocumentElementDescendantIterator : XPathDocumentBaseIterator {
private XPathDocumentNavigator end;
private string localName, namespaceUri;
private bool matchSelf;
///
/// Create an iterator that ranges over all element descendants of "root" having the specified QName.
///
public XPathDocumentElementDescendantIterator(XPathDocumentNavigator root, string name, string namespaceURI, bool matchSelf) : base(root) {
if (namespaceURI == null) throw new ArgumentNullException("namespaceURI");
this.localName = root.NameTable.Get(name);
this.namespaceUri = namespaceURI;
this.matchSelf = matchSelf;
// Find the next non-descendant node that follows "root" in document order
if (root.NodeType != XPathNodeType.Root) {
this.end = new XPathDocumentNavigator(root);
this.end.MoveToNonDescendant();
}
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentElementDescendantIterator(XPathDocumentElementDescendantIterator iter) : base(iter) {
this.end = iter.end;
this.localName = iter.localName;
this.namespaceUri = iter.namespaceUri;
this.matchSelf = iter.matchSelf;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentElementDescendantIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.matchSelf) {
this.matchSelf = false;
if (this.ctxt.IsElementMatch(this.localName, this.namespaceUri)) {
this.pos++;
return true;
}
}
if (!this.ctxt.MoveToFollowing(this.localName, this.namespaceUri, this.end))
return false;
this.pos++;
return true;
}
}
///
/// Iterate over all content descendants with a particular XPathNodeType.
///
internal class XPathDocumentKindDescendantIterator : XPathDocumentBaseIterator {
private XPathDocumentNavigator end;
private XPathNodeType typ;
private bool matchSelf;
///
/// Create an iterator that ranges over all content descendants of "root" having the specified XPathNodeType.
///
public XPathDocumentKindDescendantIterator(XPathDocumentNavigator root, XPathNodeType typ, bool matchSelf) : base(root) {
this.typ = typ;
this.matchSelf = matchSelf;
// Find the next non-descendant node that follows "root" in document order
if (root.NodeType != XPathNodeType.Root) {
this.end = new XPathDocumentNavigator(root);
this.end.MoveToNonDescendant();
}
}
///
/// Create a new iterator that is a copy of "iter".
///
public XPathDocumentKindDescendantIterator(XPathDocumentKindDescendantIterator iter) : base(iter) {
this.end = iter.end;
this.typ = iter.typ;
this.matchSelf = iter.matchSelf;
}
///
/// Create a copy of this iterator.
///
public override XPathNodeIterator Clone() {
return new XPathDocumentKindDescendantIterator(this);
}
///
/// Position the iterator to the next descendant.
///
public override bool MoveNext() {
if (this.matchSelf) {
this.matchSelf = false;
if (this.ctxt.IsKindMatch(this.typ)) {
this.pos++;
return true;
}
}
if (!this.ctxt.MoveToFollowing(this.typ, this.end))
return false;
this.pos++;
return true;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UnconditionalPolicy.cs
- OAVariantLib.cs
- BitmapEffectDrawingContent.cs
- PrivacyNoticeBindingElementImporter.cs
- Label.cs
- COM2PropertyDescriptor.cs
- RealizationDrawingContextWalker.cs
- PingOptions.cs
- SequenceDesignerAccessibleObject.cs
- Encoder.cs
- RuleAction.cs
- SchemaImporter.cs
- CfgParser.cs
- AssemblyUtil.cs
- ZoneButton.cs
- MaskedTextBox.cs
- EastAsianLunisolarCalendar.cs
- GetPageNumberCompletedEventArgs.cs
- CatalogPart.cs
- HttpPostedFile.cs
- VScrollProperties.cs
- XmlTextEncoder.cs
- FormCollection.cs
- SafeProcessHandle.cs
- IndexingContentUnit.cs
- RefExpr.cs
- UserValidatedEventArgs.cs
- EditableRegion.cs
- EventEntry.cs
- AutomationElementCollection.cs
- RectAnimationBase.cs
- EncryptedKey.cs
- DomNameTable.cs
- FigureParaClient.cs
- _CacheStreams.cs
- ColorBlend.cs
- BitmapEffectInput.cs
- SqlAliaser.cs
- WriteableBitmap.cs
- DataBindingList.cs
- PropertyChangedEventManager.cs
- SimpleHandlerFactory.cs
- TraceXPathNavigator.cs
- SettingsPropertyNotFoundException.cs
- DispatcherProcessingDisabled.cs
- ToolStripItemImageRenderEventArgs.cs
- EventSetter.cs
- ReaderContextStackData.cs
- IDictionary.cs
- StreamInfo.cs
- FrameworkElementAutomationPeer.cs
- JumpPath.cs
- DependencyObjectProvider.cs
- UnsafeNativeMethods.cs
- SingleAnimationUsingKeyFrames.cs
- TextPointer.cs
- MailSettingsSection.cs
- cookieexception.cs
- AttributeEmitter.cs
- TemplatedMailWebEventProvider.cs
- ItemsChangedEventArgs.cs
- ResourceKey.cs
- AttachmentService.cs
- AppAction.cs
- XamlPathDataSerializer.cs
- TaskFormBase.cs
- RequestStatusBarUpdateEventArgs.cs
- TextTreeRootTextBlock.cs
- Canvas.cs
- ItemList.cs
- SSmlParser.cs
- CommonDialog.cs
- StaticSiteMapProvider.cs
- Comparer.cs
- DropDownList.cs
- FontInfo.cs
- ExpressionList.cs
- SafeTimerHandle.cs
- SelectionBorderGlyph.cs
- ToolStripPanelSelectionGlyph.cs
- CodeDomComponentSerializationService.cs
- PolicyValidationException.cs
- UnsafeNativeMethodsMilCoreApi.cs
- MDIWindowDialog.cs
- EpmContentSerializer.cs
- StringAttributeCollection.cs
- LassoHelper.cs
- GridItemPatternIdentifiers.cs
- StringValueSerializer.cs
- ExpandCollapsePattern.cs
- DrawingContextDrawingContextWalker.cs
- WindowsToolbarAsMenu.cs
- ObjectDataSourceChooseTypePanel.cs
- SpnegoTokenAuthenticator.cs
- ByteStream.cs
- XmlDataCollection.cs
- DispatcherExceptionEventArgs.cs
- EditingMode.cs
- DiagnosticStrings.cs
- PreservationFileReader.cs