Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Xml / System / Xml / Dom / XmlNamedNodeMap.cs / 1 / XmlNamedNodeMap.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml { using System.Collections; // Represents a collection of nodes that can be accessed by name or index. public class XmlNamedNodeMap : IEnumerable { internal XmlNode parent; internal ArrayList nodes; internal XmlNamedNodeMap( XmlNode parent ) { this.parent = parent; this.nodes = null; } // Retrieves a XmlNode specified by name. public virtual XmlNode GetNamedItem(String name) { int offset = FindNodeOffset(name); if (offset >= 0) return(XmlNode) Nodes[offset]; return null; } // Adds a XmlNode using its Name property public virtual XmlNode SetNamedItem(XmlNode node) { if ( node == null ) return null; int offset = FindNodeOffset( node.LocalName, node.NamespaceURI ); if (offset == -1) { AddNode( node ); return null; } else { return ReplaceNodeAt( offset, node ); } } // Removes the node specified by name. public virtual XmlNode RemoveNamedItem(String name) { int offset = FindNodeOffset(name); if (offset >= 0) { return RemoveNodeAt( offset ); } return null; } // Gets the number of nodes in this XmlNamedNodeMap. public virtual int Count { get { if (nodes != null) return nodes.Count; return 0; } } // Retrieves the node at the specified index in this XmlNamedNodeMap. public virtual XmlNode Item(int index) { if (index < 0 || index >= Nodes.Count) return null; try { return(XmlNode) Nodes[index]; } catch ( ArgumentOutOfRangeException ) { throw new IndexOutOfRangeException(Res.GetString(Res.Xdom_IndexOutOfRange)); } } // // DOM Level 2 // // Retrieves a node specified by LocalName and NamespaceURI. public virtual XmlNode GetNamedItem(String localName, String namespaceURI) { int offset = FindNodeOffset( localName, namespaceURI ); if (offset >= 0) return(XmlNode) Nodes[offset]; return null; } // Removes a node specified by local name and namespace URI. public virtual XmlNode RemoveNamedItem(String localName, String namespaceURI) { int offset = FindNodeOffset( localName, namespaceURI ); if (offset >= 0) { return RemoveNodeAt( offset ); } return null; } internal ArrayList Nodes { get { if (nodes == null) nodes = new ArrayList(); return nodes; } } public virtual IEnumerator GetEnumerator() { if ( nodes == null ) { return XmlDocument.EmptyEnumerator; } else { return Nodes.GetEnumerator(); } } internal int FindNodeOffset( string name ) { int c = this.Count; for (int i = 0; i < c; i++) { XmlNode node = (XmlNode) Nodes[i]; if (name == node.Name) return i; } return -1; } internal int FindNodeOffset( string localName, string namespaceURI ) { int c = this.Count; for (int i = 0; i < c; i++) { XmlNode node = (XmlNode) Nodes[i]; if (node.LocalName == localName && node.NamespaceURI == namespaceURI) return i; } return -1; } internal virtual XmlNode AddNode( XmlNode node ) { XmlNode oldParent; if ( node.NodeType == XmlNodeType.Attribute ) oldParent = ((XmlAttribute)node).OwnerElement; else oldParent = node.ParentNode; string nodeValue = node.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert ); if (args != null) parent.BeforeEvent( args ); Nodes.Add( node ); node.SetParent( parent ); if (args != null) parent.AfterEvent( args ); return node; } internal virtual XmlNode AddNodeForLoad(XmlNode node, XmlDocument doc) { XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(node, parent); if (args != null) { doc.BeforeEvent(args); } Nodes.Add(node); node.SetParent(parent); if (args != null) { doc.AfterEvent(args); } return node; } internal virtual XmlNode RemoveNodeAt( int i ) { XmlNode oldNode = (XmlNode)Nodes[i]; string oldNodeValue = oldNode.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( oldNode, parent, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove ); if (args != null) parent.BeforeEvent( args ); Nodes.RemoveAt(i); oldNode.SetParent( null ); if (args != null) parent.AfterEvent( args ); return oldNode; } internal XmlNode ReplaceNodeAt( int i, XmlNode node ) { XmlNode oldNode = RemoveNodeAt( i ); InsertNodeAt( i, node ); return oldNode; } internal virtual XmlNode InsertNodeAt( int i, XmlNode node ) { XmlNode oldParent; if ( node.NodeType == XmlNodeType.Attribute ) oldParent = ((XmlAttribute)node).OwnerElement; else oldParent = node.ParentNode; string nodeValue = node.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert ); if (args != null) parent.BeforeEvent( args ); Nodes.Insert( i, node ); node.SetParent( parent ); if (args != null) parent.AfterEvent( args ); return node; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Xml { using System.Collections; // Represents a collection of nodes that can be accessed by name or index. public class XmlNamedNodeMap : IEnumerable { internal XmlNode parent; internal ArrayList nodes; internal XmlNamedNodeMap( XmlNode parent ) { this.parent = parent; this.nodes = null; } // Retrieves a XmlNode specified by name. public virtual XmlNode GetNamedItem(String name) { int offset = FindNodeOffset(name); if (offset >= 0) return(XmlNode) Nodes[offset]; return null; } // Adds a XmlNode using its Name property public virtual XmlNode SetNamedItem(XmlNode node) { if ( node == null ) return null; int offset = FindNodeOffset( node.LocalName, node.NamespaceURI ); if (offset == -1) { AddNode( node ); return null; } else { return ReplaceNodeAt( offset, node ); } } // Removes the node specified by name. public virtual XmlNode RemoveNamedItem(String name) { int offset = FindNodeOffset(name); if (offset >= 0) { return RemoveNodeAt( offset ); } return null; } // Gets the number of nodes in this XmlNamedNodeMap. public virtual int Count { get { if (nodes != null) return nodes.Count; return 0; } } // Retrieves the node at the specified index in this XmlNamedNodeMap. public virtual XmlNode Item(int index) { if (index < 0 || index >= Nodes.Count) return null; try { return(XmlNode) Nodes[index]; } catch ( ArgumentOutOfRangeException ) { throw new IndexOutOfRangeException(Res.GetString(Res.Xdom_IndexOutOfRange)); } } // // DOM Level 2 // // Retrieves a node specified by LocalName and NamespaceURI. public virtual XmlNode GetNamedItem(String localName, String namespaceURI) { int offset = FindNodeOffset( localName, namespaceURI ); if (offset >= 0) return(XmlNode) Nodes[offset]; return null; } // Removes a node specified by local name and namespace URI. public virtual XmlNode RemoveNamedItem(String localName, String namespaceURI) { int offset = FindNodeOffset( localName, namespaceURI ); if (offset >= 0) { return RemoveNodeAt( offset ); } return null; } internal ArrayList Nodes { get { if (nodes == null) nodes = new ArrayList(); return nodes; } } public virtual IEnumerator GetEnumerator() { if ( nodes == null ) { return XmlDocument.EmptyEnumerator; } else { return Nodes.GetEnumerator(); } } internal int FindNodeOffset( string name ) { int c = this.Count; for (int i = 0; i < c; i++) { XmlNode node = (XmlNode) Nodes[i]; if (name == node.Name) return i; } return -1; } internal int FindNodeOffset( string localName, string namespaceURI ) { int c = this.Count; for (int i = 0; i < c; i++) { XmlNode node = (XmlNode) Nodes[i]; if (node.LocalName == localName && node.NamespaceURI == namespaceURI) return i; } return -1; } internal virtual XmlNode AddNode( XmlNode node ) { XmlNode oldParent; if ( node.NodeType == XmlNodeType.Attribute ) oldParent = ((XmlAttribute)node).OwnerElement; else oldParent = node.ParentNode; string nodeValue = node.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert ); if (args != null) parent.BeforeEvent( args ); Nodes.Add( node ); node.SetParent( parent ); if (args != null) parent.AfterEvent( args ); return node; } internal virtual XmlNode AddNodeForLoad(XmlNode node, XmlDocument doc) { XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(node, parent); if (args != null) { doc.BeforeEvent(args); } Nodes.Add(node); node.SetParent(parent); if (args != null) { doc.AfterEvent(args); } return node; } internal virtual XmlNode RemoveNodeAt( int i ) { XmlNode oldNode = (XmlNode)Nodes[i]; string oldNodeValue = oldNode.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( oldNode, parent, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove ); if (args != null) parent.BeforeEvent( args ); Nodes.RemoveAt(i); oldNode.SetParent( null ); if (args != null) parent.AfterEvent( args ); return oldNode; } internal XmlNode ReplaceNodeAt( int i, XmlNode node ) { XmlNode oldNode = RemoveNodeAt( i ); InsertNodeAt( i, node ); return oldNode; } internal virtual XmlNode InsertNodeAt( int i, XmlNode node ) { XmlNode oldParent; if ( node.NodeType == XmlNodeType.Attribute ) oldParent = ((XmlAttribute)node).OwnerElement; else oldParent = node.ParentNode; string nodeValue = node.Value; XmlNodeChangedEventArgs args = parent.GetEventArgs( node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert ); if (args != null) parent.BeforeEvent( args ); Nodes.Insert( i, node ); node.SetParent( parent ); if (args != null) parent.AfterEvent( args ); return node; } } } // 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
- CriticalHandle.cs
- PropertyInfoSet.cs
- LocationEnvironment.cs
- BaseCollection.cs
- PnrpPermission.cs
- OdbcErrorCollection.cs
- PersistenceParticipant.cs
- CopyOfAction.cs
- DataGridViewCellLinkedList.cs
- MetadataUtil.cs
- CompositeControl.cs
- ParseNumbers.cs
- MultiView.cs
- ComplexTypeEmitter.cs
- PerfCounterSection.cs
- BindingExpressionBase.cs
- HtmlElementCollection.cs
- NativeObjectSecurity.cs
- TaskHelper.cs
- FamilyCollection.cs
- UIntPtr.cs
- XmlNotation.cs
- validationstate.cs
- Variant.cs
- CacheDict.cs
- MatrixCamera.cs
- DLinqTableProvider.cs
- SQLDouble.cs
- SessionPageStatePersister.cs
- ToolBarButtonClickEvent.cs
- Simplifier.cs
- DataSourceSelectArguments.cs
- SqlTriggerAttribute.cs
- DataGridViewCellValidatingEventArgs.cs
- datacache.cs
- FontNameEditor.cs
- NTAccount.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- InkCanvasSelection.cs
- HelpKeywordAttribute.cs
- LocatorPartList.cs
- ProxyWebPart.cs
- FormParameter.cs
- AspNetCompatibilityRequirementsMode.cs
- WorkflowViewManager.cs
- XsltContext.cs
- Variable.cs
- UserInitiatedRoutedEventPermission.cs
- DataObject.cs
- RightsManagementInformation.cs
- TaskFormBase.cs
- WebPartTransformerCollection.cs
- XPathConvert.cs
- CollectionContainer.cs
- IPEndPoint.cs
- AutoGeneratedField.cs
- XmlWrappingWriter.cs
- XslCompiledTransform.cs
- DeclaredTypeValidatorAttribute.cs
- DataContractSet.cs
- SizeConverter.cs
- XamlPointCollectionSerializer.cs
- CompilerResults.cs
- StrokeSerializer.cs
- ArrangedElement.cs
- IdentityModelStringsVersion1.cs
- XPathDocumentBuilder.cs
- FragmentQueryKB.cs
- BuildResult.cs
- ControlEvent.cs
- QilXmlWriter.cs
- FileFormatException.cs
- XmlSerializerFaultFormatter.cs
- Item.cs
- XmlConvert.cs
- CallbackHandler.cs
- odbcmetadatacollectionnames.cs
- FastEncoderWindow.cs
- XmlTextWriter.cs
- DataObjectSettingDataEventArgs.cs
- FileRecordSequence.cs
- SettingsContext.cs
- SQLInt32Storage.cs
- BoolExpression.cs
- ResourceCategoryAttribute.cs
- Utils.cs
- objectquery_tresulttype.cs
- AsymmetricKeyExchangeDeformatter.cs
- EdmPropertyAttribute.cs
- XmlSchemaAnyAttribute.cs
- XamlPathDataSerializer.cs
- HttpResponseInternalWrapper.cs
- SharedDp.cs
- XmlQueryType.cs
- WebPartDisplayModeCancelEventArgs.cs
- GuidelineCollection.cs
- CharAnimationBase.cs
- StylusPointDescription.cs
- HyperLinkDataBindingHandler.cs
- OrderToken.cs