Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Shared / MS / Internal / XmlHelper.cs / 1 / XmlHelper.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Implements some helper functions for Xml nodes. // //--------------------------------------------------------------------------- using System; using System.Xml; #if WINDOWS_BASE using MS.Internal.WindowsBase; #elif PRESENTATION_CORE using MS.Internal.PresentationCore; #elif PRESENTATIONFRAMEWORK using MS.Internal.PresentationFramework; #elif DRT using MS.Internal.Drt; #else #error Attempt to use FriendAccessAllowedAttribute from an unknown assembly. using MS.Internal.YourAssemblyName; #endif namespace MS.Internal { [FriendAccessAllowed] static class XmlHelper { ////// Return true if the given item is an XML node. /// internal static bool IsXmlNode(object item) { if (item != null) { Type type = item.GetType(); return type.FullName.StartsWith("System.Xml", StringComparison.Ordinal) && IsXmlNodeHelper(item); } else return false; } // separate function to avoid JIT-ing System.Xml until we have a good reason private static bool IsXmlNodeHelper(object item) { return item is System.Xml.XmlNode; } ////// Return a string by applying an XPath query to an XmlNode. /// internal static string SelectStringValue(XmlNode node, string query) { return SelectStringValue(node, query, null); } ////// Return a string by applying an XPath query to an XmlNode. /// internal static string SelectStringValue(XmlNode node, string query, XmlNamespaceManager namespaceManager) { string strValue; XmlNode result; result = node.SelectSingleNode(query, namespaceManager); if (result != null) { strValue = XmlHelper.ExtractString(result); } else { strValue = String.Empty; } return strValue; } ////// Get a string from an XmlNode (of any kind: element, attribute, etc.) /// internal static string ExtractString(XmlNode node) { string value = ""; if (node.NodeType == XmlNodeType.Element) { for (int i = 0; i < node.ChildNodes.Count; i++) { if (node.ChildNodes[i].NodeType == XmlNodeType.Text) { value += node.ChildNodes[i].Value; } } } else { value = node.Value; } return value; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // Implements some helper functions for Xml nodes. // //--------------------------------------------------------------------------- using System; using System.Xml; #if WINDOWS_BASE using MS.Internal.WindowsBase; #elif PRESENTATION_CORE using MS.Internal.PresentationCore; #elif PRESENTATIONFRAMEWORK using MS.Internal.PresentationFramework; #elif DRT using MS.Internal.Drt; #else #error Attempt to use FriendAccessAllowedAttribute from an unknown assembly. using MS.Internal.YourAssemblyName; #endif namespace MS.Internal { [FriendAccessAllowed] static class XmlHelper { ////// Return true if the given item is an XML node. /// internal static bool IsXmlNode(object item) { if (item != null) { Type type = item.GetType(); return type.FullName.StartsWith("System.Xml", StringComparison.Ordinal) && IsXmlNodeHelper(item); } else return false; } // separate function to avoid JIT-ing System.Xml until we have a good reason private static bool IsXmlNodeHelper(object item) { return item is System.Xml.XmlNode; } ////// Return a string by applying an XPath query to an XmlNode. /// internal static string SelectStringValue(XmlNode node, string query) { return SelectStringValue(node, query, null); } ////// Return a string by applying an XPath query to an XmlNode. /// internal static string SelectStringValue(XmlNode node, string query, XmlNamespaceManager namespaceManager) { string strValue; XmlNode result; result = node.SelectSingleNode(query, namespaceManager); if (result != null) { strValue = XmlHelper.ExtractString(result); } else { strValue = String.Empty; } return strValue; } ////// Get a string from an XmlNode (of any kind: element, attribute, etc.) /// internal static string ExtractString(XmlNode node) { string value = ""; if (node.NodeType == XmlNodeType.Element) { for (int i = 0; i < node.ChildNodes.Count; i++) { if (node.ChildNodes[i].NodeType == XmlNodeType.Text) { value += node.ChildNodes[i].Value; } } } else { value = node.Value; } return value; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlStreamNodeWriter.cs
- CellParagraph.cs
- ArraySubsetEnumerator.cs
- HtmlUtf8RawTextWriter.cs
- InterleavedZipPartStream.cs
- XmlDigitalSignatureProcessor.cs
- Control.cs
- PassportAuthentication.cs
- HtmlToClrEventProxy.cs
- ListContractAdapter.cs
- X509ScopedServiceCertificateElement.cs
- WebRequestModulesSection.cs
- SkinBuilder.cs
- CacheOutputQuery.cs
- _UncName.cs
- SystemDiagnosticsSection.cs
- WindowsAuthenticationEventArgs.cs
- UpdateRecord.cs
- SystemFonts.cs
- EdmItemCollection.OcAssemblyCache.cs
- IIS7WorkerRequest.cs
- PathFigureCollectionConverter.cs
- X509UI.cs
- CompositeCollection.cs
- BitmapCodecInfoInternal.cs
- TableItemStyle.cs
- HttpResponseInternalWrapper.cs
- AxisAngleRotation3D.cs
- MetaTableHelper.cs
- ThemeDirectoryCompiler.cs
- CallbackValidatorAttribute.cs
- ModelUtilities.cs
- XhtmlBasicCalendarAdapter.cs
- ConnectionProviderAttribute.cs
- BufferedGraphicsManager.cs
- AccessDataSource.cs
- PerformanceCountersBase.cs
- ExtendedPropertyDescriptor.cs
- MdiWindowListStrip.cs
- XmlSchemaComplexContentExtension.cs
- BamlResourceSerializer.cs
- SafeJobHandle.cs
- FontUnitConverter.cs
- oledbmetadatacollectionnames.cs
- HashMembershipCondition.cs
- SMSvcHost.cs
- MdiWindowListStrip.cs
- SqlDataSourceSelectingEventArgs.cs
- Hash.cs
- SqlUserDefinedAggregateAttribute.cs
- AnimatedTypeHelpers.cs
- HttpCacheParams.cs
- X509Certificate2.cs
- ConfigsHelper.cs
- HitTestWithGeometryDrawingContextWalker.cs
- EntityDataSourceUtil.cs
- DockAndAnchorLayout.cs
- CorrelationQuery.cs
- XmlArrayItemAttribute.cs
- TemplateColumn.cs
- MetaTable.cs
- EntityKeyElement.cs
- AmbiguousMatchException.cs
- IntSecurity.cs
- InstanceData.cs
- ClientBuildManager.cs
- QueueProcessor.cs
- DataTransferEventArgs.cs
- TreeIterator.cs
- TargetException.cs
- TrackingProfile.cs
- XpsImageSerializationService.cs
- NativeMethods.cs
- UriParserTemplates.cs
- ModelUIElement3D.cs
- ProxyGenerator.cs
- BigInt.cs
- InplaceBitmapMetadataWriter.cs
- StyleSelector.cs
- ConversionContext.cs
- Composition.cs
- ConnectionStringsExpressionBuilder.cs
- ToolboxSnapDragDropEventArgs.cs
- BindingNavigator.cs
- TripleDESCryptoServiceProvider.cs
- MenuItemBindingCollection.cs
- RoleManagerSection.cs
- NodeInfo.cs
- VersionPair.cs
- URIFormatException.cs
- SqlDataRecord.cs
- XPathScanner.cs
- EdmScalarPropertyAttribute.cs
- DbDataRecord.cs
- UnsafeNetInfoNativeMethods.cs
- TdsParserHelperClasses.cs
- WhitespaceRuleLookup.cs
- ClientSettingsProvider.cs
- DnsPermission.cs
- OdbcUtils.cs