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
- _OverlappedAsyncResult.cs
- LookupNode.cs
- TypeConverter.cs
- NavigationPropertyEmitter.cs
- BasicCellRelation.cs
- ScriptControlDescriptor.cs
- PropertyNames.cs
- FontStretchConverter.cs
- CapabilitiesAssignment.cs
- CompatibleComparer.cs
- remotingproxy.cs
- HelloOperationAsyncResult.cs
- LogLogRecord.cs
- CodeGeneratorOptions.cs
- ActiveDesignSurfaceEvent.cs
- IpcClientManager.cs
- GraphicsContext.cs
- WebRequestModuleElementCollection.cs
- ThemeDirectoryCompiler.cs
- EndpointAddressMessageFilterTable.cs
- SplayTreeNode.cs
- UpdatePanel.cs
- CharEntityEncoderFallback.cs
- LicFileLicenseProvider.cs
- LineBreak.cs
- wgx_sdk_version.cs
- PublisherIdentityPermission.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- CodeGotoStatement.cs
- UnsafeNativeMethods.cs
- SafeCryptContextHandle.cs
- PolicyValidator.cs
- ButtonField.cs
- XmlSerializableServices.cs
- SqlConnectionPoolGroupProviderInfo.cs
- XmlSchemaComplexContentExtension.cs
- EpmSyndicationContentSerializer.cs
- CodeGenerator.cs
- Helpers.cs
- SettingsPropertyWrongTypeException.cs
- CommonXSendMessage.cs
- RowToParametersTransformer.cs
- DispatchOperation.cs
- MultiBindingExpression.cs
- CodeObjectCreateExpression.cs
- DependencyPropertyChangedEventArgs.cs
- StrokeRenderer.cs
- RemoteWebConfigurationHost.cs
- CodeDelegateInvokeExpression.cs
- NameValuePair.cs
- XmlSchemaAttributeGroupRef.cs
- Model3D.cs
- PresentationAppDomainManager.cs
- EncodingFallbackAwareXmlTextWriter.cs
- DataAdapter.cs
- TraceSection.cs
- PartManifestEntry.cs
- ScalarType.cs
- ImageDrawing.cs
- NativeMethodsOther.cs
- safePerfProviderHandle.cs
- RegexRunnerFactory.cs
- ContentElementAutomationPeer.cs
- JsonUriDataContract.cs
- QilFunction.cs
- PromptStyle.cs
- PackageStore.cs
- WebPart.cs
- UserInitiatedNavigationPermission.cs
- FrameworkContextData.cs
- EventMappingSettings.cs
- PatternMatcher.cs
- SecurityRuntime.cs
- XPathDocumentIterator.cs
- ConstructorBuilder.cs
- StringSorter.cs
- ObservableDictionary.cs
- EnumerableRowCollection.cs
- LayoutInformation.cs
- CodeDirectionExpression.cs
- Base64Decoder.cs
- DataGridViewCheckBoxCell.cs
- NetworkInformationPermission.cs
- TemplateBamlRecordReader.cs
- Graph.cs
- CanonicalFontFamilyReference.cs
- ClientProxyGenerator.cs
- StringDictionary.cs
- CommandField.cs
- ResolvePPIDRequest.cs
- HMACMD5.cs
- PrimitiveDataContract.cs
- ClientSettingsStore.cs
- PrintDialogException.cs
- SamlAssertion.cs
- CompletionProxy.cs
- GeneralTransformCollection.cs
- DataGridBoolColumn.cs
- EventWaitHandleSecurity.cs
- StorageBasedPackageProperties.cs