Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / XmlUtils / System / Xml / Xsl / Runtime / WhitespaceRuleReader.cs / 1 / WhitespaceRuleReader.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using MS.Internal.Xml;
namespace System.Xml.Xsl.Runtime {
///
///
internal class WhitespaceRuleReader : XmlWrappingReader {
private WhitespaceRuleLookup wsRules;
private BitStack stkStrip;
private bool shouldStrip, preserveAdjacent;
private string val;
private XmlCharType xmlCharType = XmlCharType.Instance;
static public XmlReader CreateReader(XmlReader baseReader, WhitespaceRuleLookup wsRules) {
if (wsRules == null) {
return baseReader; // There is no rules to process
}
XmlReaderSettings readerSettings = baseReader.Settings;
if (readerSettings != null) {
if (readerSettings.IgnoreWhitespace) {
return baseReader; // V2 XmlReader that strips all WS
}
} else {
XmlTextReader txtReader = baseReader as XmlTextReader;
if (txtReader != null && txtReader.WhitespaceHandling == WhitespaceHandling.None) {
return baseReader; // V1 XmlTextReader that strips all WS
}
XmlTextReaderImpl txtReaderImpl = baseReader as XmlTextReaderImpl;
if (txtReaderImpl != null && txtReaderImpl.WhitespaceHandling == WhitespaceHandling.None) {
return baseReader; // XmlTextReaderImpl that strips all WS
}
}
return new WhitespaceRuleReader(baseReader, wsRules);
}
private WhitespaceRuleReader(XmlReader baseReader, WhitespaceRuleLookup wsRules) : base(baseReader) {
Debug.Assert(wsRules != null);
this.val = null;
this.stkStrip = new BitStack();
this.shouldStrip = false;
this.preserveAdjacent = false;
this.wsRules = wsRules;
this.wsRules.Atomize(baseReader.NameTable);
}
///
/// Override Value in order to possibly prepend extra whitespace.
///
public override string Value {
get { return (this.val == null) ? base.Value : this.val; }
}
///
/// Override Read in order to search for strippable whitespace, to concatenate adjacent text nodes, and to
/// resolve entities.
///
public override bool Read() {
XmlCharType xmlCharType = XmlCharType.Instance;
string ws = null;
// Clear text value
this.val = null;
while (base.Read()) {
switch (base.NodeType) {
case XmlNodeType.Element:
// Push boolean indicating whether whitespace children of this element should be stripped
if (!base.IsEmptyElement) {
this.stkStrip.PushBit(this.shouldStrip);
// Strip if rules say we should and we're not within the scope of xml:space="preserve"
this.shouldStrip = wsRules.ShouldStripSpace(base.LocalName, base.NamespaceURI) && (base.XmlSpace != XmlSpace.Preserve);
}
break;
case XmlNodeType.EndElement:
// Restore parent shouldStrip setting
this.shouldStrip = this.stkStrip.PopBit();
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
// If preserving adjacent text, don't perform any further checks
if (this.preserveAdjacent)
return true;
if (this.shouldStrip) {
// Reader may report whitespace as Text or CDATA
if (xmlCharType.IsOnlyWhitespace(base.Value))
goto case XmlNodeType.Whitespace;
// If whitespace was cached, then prepend it to text or CDATA value
if (ws != null)
this.val = string.Concat(ws, base.Value);
// Preserve adjacent whitespace
this.preserveAdjacent = true;
return true;
}
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
// If preserving adjacent text, don't perform any further checks
if (this.preserveAdjacent)
return true;
if (this.shouldStrip) {
// Save whitespace until it can be determined whether it will be stripped
if (ws == null)
ws = base.Value;
else
ws = string.Concat(ws, base.Value);
// Read next event
continue;
}
break;
case XmlNodeType.EntityReference:
reader.ResolveEntity();
break;
case XmlNodeType.EndEntity:
// Read next event
continue;
}
// No longer preserve adjacent space
this.preserveAdjacent = false;
return true;
}
return false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using MS.Internal.Xml;
namespace System.Xml.Xsl.Runtime {
///
///
internal class WhitespaceRuleReader : XmlWrappingReader {
private WhitespaceRuleLookup wsRules;
private BitStack stkStrip;
private bool shouldStrip, preserveAdjacent;
private string val;
private XmlCharType xmlCharType = XmlCharType.Instance;
static public XmlReader CreateReader(XmlReader baseReader, WhitespaceRuleLookup wsRules) {
if (wsRules == null) {
return baseReader; // There is no rules to process
}
XmlReaderSettings readerSettings = baseReader.Settings;
if (readerSettings != null) {
if (readerSettings.IgnoreWhitespace) {
return baseReader; // V2 XmlReader that strips all WS
}
} else {
XmlTextReader txtReader = baseReader as XmlTextReader;
if (txtReader != null && txtReader.WhitespaceHandling == WhitespaceHandling.None) {
return baseReader; // V1 XmlTextReader that strips all WS
}
XmlTextReaderImpl txtReaderImpl = baseReader as XmlTextReaderImpl;
if (txtReaderImpl != null && txtReaderImpl.WhitespaceHandling == WhitespaceHandling.None) {
return baseReader; // XmlTextReaderImpl that strips all WS
}
}
return new WhitespaceRuleReader(baseReader, wsRules);
}
private WhitespaceRuleReader(XmlReader baseReader, WhitespaceRuleLookup wsRules) : base(baseReader) {
Debug.Assert(wsRules != null);
this.val = null;
this.stkStrip = new BitStack();
this.shouldStrip = false;
this.preserveAdjacent = false;
this.wsRules = wsRules;
this.wsRules.Atomize(baseReader.NameTable);
}
///
/// Override Value in order to possibly prepend extra whitespace.
///
public override string Value {
get { return (this.val == null) ? base.Value : this.val; }
}
///
/// Override Read in order to search for strippable whitespace, to concatenate adjacent text nodes, and to
/// resolve entities.
///
public override bool Read() {
XmlCharType xmlCharType = XmlCharType.Instance;
string ws = null;
// Clear text value
this.val = null;
while (base.Read()) {
switch (base.NodeType) {
case XmlNodeType.Element:
// Push boolean indicating whether whitespace children of this element should be stripped
if (!base.IsEmptyElement) {
this.stkStrip.PushBit(this.shouldStrip);
// Strip if rules say we should and we're not within the scope of xml:space="preserve"
this.shouldStrip = wsRules.ShouldStripSpace(base.LocalName, base.NamespaceURI) && (base.XmlSpace != XmlSpace.Preserve);
}
break;
case XmlNodeType.EndElement:
// Restore parent shouldStrip setting
this.shouldStrip = this.stkStrip.PopBit();
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
// If preserving adjacent text, don't perform any further checks
if (this.preserveAdjacent)
return true;
if (this.shouldStrip) {
// Reader may report whitespace as Text or CDATA
if (xmlCharType.IsOnlyWhitespace(base.Value))
goto case XmlNodeType.Whitespace;
// If whitespace was cached, then prepend it to text or CDATA value
if (ws != null)
this.val = string.Concat(ws, base.Value);
// Preserve adjacent whitespace
this.preserveAdjacent = true;
return true;
}
break;
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
// If preserving adjacent text, don't perform any further checks
if (this.preserveAdjacent)
return true;
if (this.shouldStrip) {
// Save whitespace until it can be determined whether it will be stripped
if (ws == null)
ws = base.Value;
else
ws = string.Concat(ws, base.Value);
// Read next event
continue;
}
break;
case XmlNodeType.EntityReference:
reader.ResolveEntity();
break;
case XmlNodeType.EndEntity:
// Read next event
continue;
}
// No longer preserve adjacent space
this.preserveAdjacent = false;
return true;
}
return false;
}
}
}
// 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
- RolePrincipal.cs
- CompilerTypeWithParams.cs
- EventDescriptorCollection.cs
- FunctionMappingTranslator.cs
- VariantWrapper.cs
- BinHexEncoding.cs
- WorkflowStateRollbackService.cs
- TypeExtensionConverter.cs
- URLIdentityPermission.cs
- StdRegProviderWrapper.cs
- Rotation3D.cs
- DefaultPropertiesToSend.cs
- PropertyDescriptors.cs
- Property.cs
- ExceptionUtil.cs
- EncodingInfo.cs
- WebException.cs
- AsymmetricAlgorithm.cs
- RuleSettingsCollection.cs
- MultiPropertyDescriptorGridEntry.cs
- MemoryStream.cs
- BaseTemplateParser.cs
- ScriptingRoleServiceSection.cs
- GenerateTemporaryAssemblyTask.cs
- PartitionedStreamMerger.cs
- AccessDataSource.cs
- StructuralCache.cs
- WmlMobileTextWriter.cs
- InfiniteIntConverter.cs
- Thickness.cs
- XPathExpr.cs
- TraceEventCache.cs
- FileLogRecordHeader.cs
- HtmlButton.cs
- Point3DAnimation.cs
- XmlSchemaImporter.cs
- EntityContainerAssociationSetEnd.cs
- StorageScalarPropertyMapping.cs
- VisualCollection.cs
- XmlReflectionMember.cs
- ContractCodeDomInfo.cs
- LocatorPartList.cs
- AstNode.cs
- Geometry.cs
- EpmSourceTree.cs
- FieldAccessException.cs
- PartialCachingControl.cs
- TableLayoutPanel.cs
- ManifestResourceInfo.cs
- AssemblyCacheEntry.cs
- Attributes.cs
- StaticTextPointer.cs
- Byte.cs
- Int32AnimationBase.cs
- TextRunTypographyProperties.cs
- ReadWriteObjectLock.cs
- DispatchWrapper.cs
- XmlILOptimizerVisitor.cs
- _FixedSizeReader.cs
- FixedSOMPage.cs
- RenderingBiasValidation.cs
- SafeLibraryHandle.cs
- ToolStripButton.cs
- DataReaderContainer.cs
- ActivityExecutorSurrogate.cs
- OracleTimeSpan.cs
- HandledEventArgs.cs
- Itemizer.cs
- XmlAtomErrorReader.cs
- AttachedPropertyMethodSelector.cs
- mactripleDES.cs
- listitem.cs
- XComponentModel.cs
- StructureChangedEventArgs.cs
- UInt32Storage.cs
- RoleGroupCollection.cs
- PointLightBase.cs
- LateBoundBitmapDecoder.cs
- PromptEventArgs.cs
- ServiceSettingsResponseInfo.cs
- HttpListener.cs
- AppDomainManager.cs
- NotifyInputEventArgs.cs
- InlineCollection.cs
- ZipIOExtraFieldElement.cs
- Block.cs
- TargetConverter.cs
- RegisteredDisposeScript.cs
- PrintDialog.cs
- cookiecontainer.cs
- InstanceKeyCompleteException.cs
- LinqDataSourceInsertEventArgs.cs
- TextParagraph.cs
- Dispatcher.cs
- RTLAwareMessageBox.cs
- EdmTypeAttribute.cs
- SqlDataReaderSmi.cs
- QuaternionRotation3D.cs
- XmlCodeExporter.cs
- WebServiceTypeData.cs