From: Oleg T. <he...@us...> - 2005-10-25 21:34:02
|
Update of /cvsroot/mvp-xml/Common/v2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1205/v2/src Modified Files: Common.csproj XmlBaseAwareXmlTextReader.cs XmlNamespaces.cs XmlNodeListFactory.cs Added Files: XmlFragmentStream.cs XmlNodeFactory.cs Log Message: --- NEW FILE: XmlNodeFactory.cs --- #region using using System; using System.Xml; using System.Xml.Serialization; using System.Xml.XPath; using Mvp.Xml.Common.XPath; #endregion namespace Mvp.Xml.Common { /// <summary> /// Creates <see cref="XmlNode"/> wrapper instances /// for different XML APIs, for use in XML serialization. /// </summary> /// <remarks> /// <see cref="XmlNode"/> instances returned by this factory only /// support the <see cref="XmlNode.WriteTo"/> and <see cref="XmlNode.WriteContentTo"/> /// methods, as they are intended for use only for serialization, and to avoid /// <see cref="XmlDocument"/> loading for fast performance. All other members /// will throw an <see cref="NotSupportedException"/>. /// <para>Author: Daniel Cazzulino, kz...@gm...</para> /// See: http://weblogs.asp.net/cazzu/archive/2004/05/31/144922.aspx and /// http://weblogs.asp.net/cazzu/posts/XmlMessagePerformance.aspx. /// </remarks> public class XmlNodeFactory { private XmlNodeFactory() {} #region Create overloads /// <summary> /// Creates an <see cref="XmlNode"/> wrapper for any object, /// to be serialized through the <see cref="XmlSerializer"/>. /// </summary> /// <param name="value">The object to wrap.</param> /// <returns>A node that can only be used for XML serialization.</returns> public static XmlNode Create(object value) { return new ObjectNode(value); } /// <summary> /// Creates an <see cref="XmlNode"/> serializable /// wrapper for an <see cref="XPathNavigator"/>. /// </summary> /// <param name="navigator">The navigator to wrap.</param> /// <returns>A node that can only be used for XML serialization.</returns> public static XmlNode Create(XPathNavigator navigator) { return new XPathNavigatorNode(navigator); } /// <summary> /// Creates an <see cref="XmlNode"/> serializable /// wrapper for an <see cref="XmlReader"/>. /// </summary> /// <param name="reader">The reader to wrap.</param> /// <returns>A node that can only be used for XML serialization.</returns> /// <remarks> /// After serialization, the reader is automatically closed. /// </remarks> public static XmlNode Create(XmlReader reader) { return Create(reader, false); } /// <summary> /// Creates an <see cref="XmlDocument"/> serializable /// wrapper for an <see cref="XPathNavigator"/>. /// </summary> /// <param name="reader">The reader to wrap.</param> /// <param name="defaultAttrs">Whether default attributes should be serialized.</param> /// <returns>A document that can only be used for XML serialization.</returns> /// <remarks> /// After serialization, the reader is automatically closed. /// </remarks> public static XmlNode Create(XmlReader reader, bool defaultAttrs) { return new XmlReaderNode(reader, defaultAttrs); } #endregion Create overloads #region SerializableNode private abstract class SerializableNode : XmlElement { public SerializableNode() : base("", "dummy", "", new XmlDocument()) {} public override XmlNode AppendChild(XmlNode newChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlAttributeCollection Attributes { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string BaseURI { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNodeList ChildNodes { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode Clone() { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode CloneNode(bool deep) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode FirstChild { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string GetNamespaceOfPrefix(string prefix) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override string GetPrefixOfNamespace(string namespaceURI) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override bool HasChildNodes { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string InnerText { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } set { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string InnerXml { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } set { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode InsertAfter(XmlNode newChild, XmlNode refChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode InsertBefore(XmlNode newChild, XmlNode refChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override bool IsReadOnly { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode LastChild { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string LocalName { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string Name { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string NamespaceURI { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode NextSibling { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNodeType NodeType { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override void Normalize() { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override string OuterXml { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlDocument OwnerDocument { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode ParentNode { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string Prefix { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } set { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlNode PrependChild(XmlNode newChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode PreviousSibling { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override void RemoveAll() { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode RemoveChild(XmlNode oldChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override bool Supports(string feature, string version) { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } public override XmlElement this[string localname, string ns] { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override XmlElement this[string name] { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override string Value { get { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } set { throw new NotSupportedException(SR.XmlDocumentFactory_NotImplementedDOM); } } public override void WriteContentTo(XmlWriter w) { WriteTo(w); } public abstract override void WriteTo(XmlWriter w); } #endregion SerializableNode #region XPathNavigatorNode private class XPathNavigatorNode : SerializableNode { private XPathNavigator _navigator; public XPathNavigatorNode() {} public XPathNavigatorNode(XPathNavigator navigator) { _navigator = navigator; } public override void WriteTo(XmlWriter w) { w.WriteNode(_navigator.ReadSubtree(), false); } } #endregion XPathNavigatorNode #region XmlReaderNode private class XmlReaderNode : SerializableNode { private XmlReader _reader; private bool _default; public XmlReaderNode() {} public XmlReaderNode(XmlReader reader, bool defaultAttrs) { _reader = reader; _reader.MoveToContent(); _default = defaultAttrs; } public override void WriteTo(XmlWriter w) { w.WriteNode(_reader, _default); _reader.Close(); } } #endregion XmlReaderNode #region ObjectNode private class ObjectNode : SerializableNode { private object serializableObject; public ObjectNode() {} public ObjectNode(object serializableObject) { this.serializableObject = serializableObject; } public override void WriteTo(XmlWriter w) { XmlSerializer ser = new XmlSerializer(serializableObject.GetType()); ser.Serialize(w, serializableObject); } } #endregion XmlReaderNode } } Index: XmlNodeListFactory.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/XmlNodeListFactory.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XmlNodeListFactory.cs 16 Oct 2005 16:51:24 -0000 1.1 +++ XmlNodeListFactory.cs 25 Oct 2005 21:33:43 -0000 1.2 @@ -2,6 +2,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Xml; using System.Xml.XPath; @@ -9,176 +10,178 @@ namespace Mvp.Xml.Common { - /// <summary> - /// Constructs <see cref="XmlNodeList"/> instances from - /// <see cref="XPathNodeIterator"/> objects. - /// </summary> - /// <remarks>See http://weblogs.asp.net/cazzu/archive/2004/04/14/113479.aspx. - /// <para>Author: Daniel Cazzulino, kz...@gm...</para> - /// </remarks> - public sealed class XmlNodeListFactory - { - private XmlNodeListFactory() { } - - #region Public members + /// <summary> + /// Constructs <see cref="XmlNodeList"/> instances from + /// <see cref="XPathNodeIterator"/> objects. + /// </summary> + /// <remarks>See http://weblogs.asp.net/cazzu/archive/2004/04/14/113479.aspx. + /// <para>Author: Daniel Cazzulino, kz...@gm...</para> + /// <para>Contributors: Oleg Tkachenko, ol...@xm...</para> + /// </remarks> + public sealed class XmlNodeListFactory + { + private XmlNodeListFactory() {} - /// <summary> - /// Creates an instance of a <see cref="XmlNodeList"/> that allows - /// enumerating <see cref="XmlNode"/> elements in the iterator. - /// </summary> - /// <param name="iterator">The result of a previous node selection - /// through an <see cref="XPathNavigator"/> query.</param> - /// <returns>An initialized list ready to be enumerated.</returns> - /// <remarks>The underlying XML store used to issue the query must be - /// an object inheriting <see cref="XmlNode"/>, such as - /// <see cref="XmlDocument"/>.</remarks> - public static XmlNodeList CreateNodeList(XPathNodeIterator iterator) - { - return new XmlNodeListIterator(iterator); - } + #region Public members - #endregion Public members + /// <summary> + /// Creates an instance of a <see cref="XmlNodeList"/> that allows + /// enumerating <see cref="XmlNode"/> elements in the iterator. + /// </summary> + /// <param name="iterator">The result of a previous node selection + /// through an <see cref="XPathNavigator"/> query.</param> + /// <returns>An initialized list ready to be enumerated.</returns> + /// <remarks>The underlying XML store used to issue the query must be + /// an object inheriting <see cref="XmlNode"/>, such as + /// <see cref="XmlDocument"/>.</remarks> + public static XmlNodeList CreateNodeList(XPathNodeIterator iterator) + { + return new XmlNodeListIterator(iterator); + } - #region XmlNodeListIterator + #endregion Public members - private class XmlNodeListIterator : XmlNodeList - { - XPathNodeIterator _iterator; - ArrayList _nodes = new ArrayList(); + #region XmlNodeListIterator - public XmlNodeListIterator(XPathNodeIterator iterator) - { - _iterator = iterator.Clone(); - } + private class XmlNodeListIterator: XmlNodeList + { + XPathNodeIterator _iterator; + IList<XmlNode> _nodes = new List<XmlNode>(); - public override IEnumerator GetEnumerator() - { - return new XmlNodeListEnumerator(this); - } + public XmlNodeListIterator(XPathNodeIterator iterator) + { + _iterator = iterator.Clone(); + } - public override XmlNode Item(int index) - { - if (index >= _nodes.Count) - ReadTo(index); - // Compatible behavior with .NET - if (index >= _nodes.Count || index < 0) - return null; - return (XmlNode)_nodes[index]; - } + public override IEnumerator GetEnumerator() + { + return new XmlNodeListEnumerator(this); + } + + public override XmlNode Item(int index) + { - public override int Count - { - get - { - if (!_done) ReadToEnd(); - return _nodes.Count; - } - } + if (index >= _nodes.Count) + ReadTo(index); + // Compatible behavior with .NET + if (index >= _nodes.Count || index < 0) + return null; + return _nodes[index]; + } + public override int Count + { + get + { + if (!_done) ReadToEnd(); + return _nodes.Count; + } + } + - /// <summary> - /// Reads the entire iterator. - /// </summary> - private void ReadToEnd() - { - while (_iterator.MoveNext()) - { - IHasXmlNode node = _iterator.Current as IHasXmlNode; - // Check IHasXmlNode interface. - if (node == null) - throw new ArgumentException(SR.XmlNodeListFactory_IHasXmlNodeMissing); - _nodes.Add(node.GetNode()); - } - _done = true; - } + /// <summary> + /// Reads the entire iterator. + /// </summary> + private void ReadToEnd() + { + while (_iterator.MoveNext()) + { + IHasXmlNode node = _iterator.Current as IHasXmlNode; + // Check IHasXmlNode interface. + if (node == null) + throw new ArgumentException(SR.XmlNodeListFactory_IHasXmlNodeMissing); + _nodes.Add(node.GetNode()); + } + _done = true; + } - /// <summary> - /// Reads up to the specified index, or until the - /// iterator is consumed. - /// </summary> - private void ReadTo(int to) - { - while (_nodes.Count <= to) - { - if (_iterator.MoveNext()) - { - IHasXmlNode node = _iterator.Current as IHasXmlNode; - // Check IHasXmlNode interface. - if (node == null) - throw new ArgumentException(SR.XmlNodeListFactory_IHasXmlNodeMissing); - _nodes.Add(node.GetNode()); - } - else - { - _done = true; - return; - } - } - } + /// <summary> + /// Reads up to the specified index, or until the + /// iterator is consumed. + /// </summary> + private void ReadTo(int to) + { + while (_nodes.Count <= to) + { + if (_iterator.MoveNext()) + { + IHasXmlNode node = _iterator.Current as IHasXmlNode; + // Check IHasXmlNode interface. + if (node == null) + throw new ArgumentException(SR.XmlNodeListFactory_IHasXmlNodeMissing); + _nodes.Add(node.GetNode()); + } + else + { + _done = true; + return; + } + } + } - /// <summary> - /// Flags that the iterator has been consumed. - /// </summary> - private bool Done - { - get { return _done; } - } bool _done; + /// <summary> + /// Flags that the iterator has been consumed. + /// </summary> + private bool Done + { + get { return _done; } + } bool _done; - /// <summary> - /// Current count of nodes in the iterator (read so far). - /// </summary> - private int CurrentPosition - { - get { return _nodes.Count; } - } + /// <summary> + /// Current count of nodes in the iterator (read so far). + /// </summary> + private int CurrentPosition + { + get { return _nodes.Count; } + } - #region XmlNodeListEnumerator + #region XmlNodeListEnumerator - private class XmlNodeListEnumerator : IEnumerator - { - XmlNodeListIterator _iterator; - int _position = -1; + private class XmlNodeListEnumerator: IEnumerator + { + XmlNodeListIterator _iterator; + int _position = -1; - public XmlNodeListEnumerator(XmlNodeListIterator iterator) - { - _iterator = iterator; - } + public XmlNodeListEnumerator(XmlNodeListIterator iterator) + { + _iterator = iterator; + } - #region IEnumerator Members + #region IEnumerator Members - void System.Collections.IEnumerator.Reset() - { - _position = -1; - } + void System.Collections.IEnumerator.Reset() + { + _position = -1; + } - bool System.Collections.IEnumerator.MoveNext() - { - _position++; - _iterator.ReadTo(_position); + bool System.Collections.IEnumerator.MoveNext() + { + _position++; + _iterator.ReadTo(_position); - // If we reached the end and our index is still - // bigger, there're no more items. - if (_iterator.Done && _position >= _iterator.CurrentPosition) - return false; + // If we reached the end and our index is still + // bigger, there're no more items. + if (_iterator.Done && _position >= _iterator.CurrentPosition) + return false; - return true; - } + return true; + } - object System.Collections.IEnumerator.Current - { - get - { - return _iterator[_position]; - } - } + object System.Collections.IEnumerator.Current + { + get + { + return _iterator[_position]; + } + } - #endregion - } + #endregion + } - #endregion XmlNodeListEnumerator - } + #endregion XmlNodeListEnumerator + } - #endregion XmlNodeListIterator - } + #endregion XmlNodeListIterator + } } --- NEW FILE: XmlFragmentStream.cs --- #region using using System; using System.IO; using System.Text; #endregion using namespace Mvp.Xml.Common { /// <summary> /// Allows streams without a root element (i.e. multiple document /// fragments) to be passed to an <see cref="System.Xml.XmlReader"/>. /// </summary> /// <remarks>A faked root element is added at the stream /// level to enclose the fragments, which can be customized /// using the overloaded constructors. /// <para>Author: Daniel Cazzulino, kz...@gm...</para> /// See: http://weblogs.asp.net/cazzu/archive/2004/04/23/119263.aspx. /// </remarks> public class XmlFragmentStream : Stream { #region Fields // Holds the inner stream with the XML fragments. Stream _stream; bool _first = true; bool _done = false; bool _eof = false; // TODO: there's a potential encoding issue here. byte[] _rootstart = UTF8Encoding.UTF8.GetBytes("<root>"); byte[] _rootend = UTF8Encoding.UTF8.GetBytes("</root>"); int _endidx = -1; #endregion Fields #region Ctors /// <summary> /// Initializes the class with the underlying stream to use, and /// uses the default <root> container element. /// </summary> /// <param name="innerStream">The stream to read from.</param> public XmlFragmentStream(Stream innerStream) { if (innerStream == null) throw new ArgumentNullException("innerStream"); _stream = innerStream; } /// <summary> /// Initializes the class with the underlying stream to use, with /// a custom root element. /// </summary> /// <param name="innerStream">The stream to read from.</param> /// <param name="rootName">Custom root element name to use.</param> public XmlFragmentStream(Stream innerStream, string rootName) : this (innerStream) { _rootstart = UTF8Encoding.UTF8.GetBytes("<" + rootName + ">"); _rootend = UTF8Encoding.UTF8.GetBytes("</" + rootName + ">"); } /// <summary> /// Initializes the class with the underlying stream to use, with /// a custom root element. /// </summary> /// <param name="innerStream">The stream to read from.</param> /// <param name="rootName">Custom root element name to use.</param> /// <param name="ns">The namespace of the root element.</param> public XmlFragmentStream(Stream innerStream, string rootName, string ns) : this (innerStream) { _rootstart = UTF8Encoding.UTF8.GetBytes("<" + rootName + " xmlns=\"" + ns + "\">"); _rootend = UTF8Encoding.UTF8.GetBytes("</" + rootName + ">"); } #endregion Ctors #region Stream abstract implementation /// <summary>See <see cref="Stream.Flush"/>.</summary> public override void Flush() { _stream.Flush(); } /// <summary>See <see cref="Stream.Seek"/>.</summary> public override long Seek(long offset, SeekOrigin origin) { return _stream.Seek(offset, origin); } /// <summary>See <see cref="Stream.SetLength"/>.</summary> public override void SetLength(long value) { _stream.SetLength(value); } /// <summary>See <see cref="Stream.Write"/>.</summary> public override void Write(byte[] buffer, int offset, int count) { _stream.Write(buffer, offset, count); } /// <summary>See <see cref="Stream.CanRead"/>.</summary> public override bool CanRead { get { return _stream.CanRead; } } /// <summary>See <see cref="Stream.CanSeek"/>.</summary> public override bool CanSeek { get { return _stream.CanSeek; } } /// <summary>See <see cref="Stream.CanWrite"/>.</summary> public override bool CanWrite { get { return _stream.CanWrite; } } /// <summary>See <see cref="Stream.Length"/>.</summary> public override long Length { get { return _stream.Length; } } /// <summary>See <see cref="Stream.Position"/>.</summary> public override long Position { get { return _stream.Position; } set { _stream.Position = value; } } #endregion Stream abstract implementation #region Read method /// <summary>See <see cref="Stream.Read"/>.</summary> public override int Read(byte[] buffer, int offset, int count) { if (_done) { if(!_eof) { _eof = true; return 0; } else { throw new System.IO.EndOfStreamException(SR.GetString(SR.XmlFragmentStream_EOF)); } } // If this is the first one, return the wrapper root element. if (_first) { _rootstart.CopyTo(buffer, 0); _stream.Read(buffer, _rootstart.Length, count - _rootstart.Length); _first = false; return count; } // We have a pending closing wrapper root element. if (_endidx != -1) { for (int i = _endidx; i < _rootend.Length; i++) { buffer[i] = _rootend[i]; } return _rootend.Length - _endidx; } int ret = _stream.Read(buffer, offset, count); // Did we reached the end? if (ret < count) { _rootend.CopyTo(buffer, ret); if (count - ret > _rootend.Length) { _done = true; return ret + _rootend.Length; } else { _endidx = count - ret; return count; } } return ret; } #endregion Read method } } Index: Common.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/Common.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Common.csproj 24 Oct 2005 12:08:27 -0000 1.3 +++ Common.csproj 25 Oct 2005 21:33:43 -0000 1.4 @@ -97,9 +97,11 @@ <Compile Include="XmlFirstUpperReader.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="XmlFragmentStream.cs" /> <Compile Include="XmlNamespaces.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="XmlNodeFactory.cs" /> <Compile Include="XmlNodeListFactory.cs"> <SubType>Code</SubType> </Compile> @@ -109,6 +111,7 @@ <Compile Include="XPath\DynamicContext.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="XPath\IHasXPathNavigator.cs" /> <Compile Include="XPath\IndexingXPathNavigator.cs"> <SubType>Code</SubType> </Compile> Index: XmlBaseAwareXmlTextReader.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/XmlBaseAwareXmlTextReader.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- XmlBaseAwareXmlTextReader.cs 24 Oct 2005 12:08:27 -0000 1.2 +++ XmlBaseAwareXmlTextReader.cs 25 Oct 2005 21:33:43 -0000 1.3 @@ -9,28 +9,28 @@ namespace Mvp.Xml.Common { - /// <summary> - /// XmlTextReader supporting <a href="http://www.w3.org/TR/xmlbase/">XML Base</a>. - /// </summary> - /// <remarks> - /// <para>Author: Oleg Tkachenko, ol...@xm...</para> - /// </remarks> - public class XmlBaseAwareXmlTextReader : XmlTextReader + /// <summary> + /// XmlTextReader supporting <a href="http://www.w3.org/TR/xmlbase/">XML Base</a>. + /// </summary> + /// <remarks> + /// <para>Author: Oleg Tkachenko, ol...@xm...</para> + /// </remarks> + public class XmlBaseAwareXmlTextReader : XmlTextReader { #region private private XmlBaseState _state = new XmlBaseState(); private Stack<XmlBaseState> _states = null; - #endregion + #endregion #region constructors - + /// <summary> /// Creates XmlBaseAwareXmlTextReader instance for given URI. /// </summary> public XmlBaseAwareXmlTextReader(string uri) - : base(uri) + : base(uri) { _state.BaseUri = new Uri(base.BaseURI); } @@ -40,7 +40,7 @@ /// name table. /// </summary> public XmlBaseAwareXmlTextReader(string uri, XmlNameTable nt) - : base(uri, nt) + : base(uri, nt) { _state.BaseUri = new Uri(base.BaseURI); } @@ -49,14 +49,14 @@ /// Creates XmlBaseAwareXmlTextReader instance for given TextReader. /// </summary> public XmlBaseAwareXmlTextReader(TextReader reader) - : base(reader) {} + : base(reader) { } /// <summary> /// Creates XmlBaseAwareXmlTextReader instance for given uri and /// TextReader. /// </summary> public XmlBaseAwareXmlTextReader(string uri, TextReader reader) - : base(uri, reader) + : base(uri, reader) { _state.BaseUri = new Uri(base.BaseURI); } @@ -66,14 +66,14 @@ /// and name table. /// </summary> public XmlBaseAwareXmlTextReader(TextReader reader, XmlNameTable nt) - : base(reader, nt) {} + : base(reader, nt) { } /// <summary> /// Creates XmlBaseAwareXmlTextReader instance for given uri, name table /// and TextReader. /// </summary> public XmlBaseAwareXmlTextReader(string uri, TextReader reader, XmlNameTable nt) - : base(uri, reader, nt) + : base(uri, reader, nt) { _state.BaseUri = new Uri(base.BaseURI); } @@ -82,13 +82,13 @@ /// Creates XmlBaseAwareXmlTextReader instance for given stream. /// </summary> public XmlBaseAwareXmlTextReader(Stream stream) - : base(stream) {} + : base(stream) { } /// <summary> /// Creates XmlBaseAwareXmlTextReader instance for given uri and stream. /// </summary> public XmlBaseAwareXmlTextReader(string uri, Stream stream) - : base(uri, stream) + : base(uri, stream) { _state.BaseUri = new Uri(base.BaseURI); } @@ -98,14 +98,14 @@ /// and name table. /// </summary> public XmlBaseAwareXmlTextReader(Stream stream, XmlNameTable nt) - : base(stream, nt) {} + : base(stream, nt) { } /// <summary> /// Creates XmlBaseAwareXmlTextReader instance for given stream, /// uri and name table. /// </summary> public XmlBaseAwareXmlTextReader(string uri, Stream stream, XmlNameTable nt) - : base(uri, stream, nt) + : base(uri, stream, nt) { _state.BaseUri = new Uri(base.BaseURI); } @@ -121,7 +121,7 @@ { get { - return _state.BaseUri==null? "" : _state.BaseUri.AbsoluteUri; + return _state.BaseUri == null ? "" : _state.BaseUri.AbsoluteUri; } } @@ -129,47 +129,47 @@ /// See <see cref="XmlTextReader.Read"/>. /// </summary> public override bool Read() - { + { bool baseRead = base.Read(); - if (baseRead) + if (baseRead) { if (base.NodeType == XmlNodeType.Element && - base.HasAttributes) + base.HasAttributes) { string baseAttr = GetAttribute("xml:base"); if (baseAttr == null) - return baseRead; + return baseRead; Uri newBaseUri = null; if (_state.BaseUri == null) - newBaseUri = new Uri(baseAttr); + newBaseUri = new Uri(baseAttr); else - newBaseUri = new Uri(_state.BaseUri, baseAttr); + newBaseUri = new Uri(_state.BaseUri, baseAttr); if (_states == null) _states = new Stack<XmlBaseState>(); //Push current state and allocate new one - _states.Push(_state); + _states.Push(_state); _state = new XmlBaseState(newBaseUri, base.Depth); } - else if (base.NodeType == XmlNodeType.EndElement) + else if (base.NodeType == XmlNodeType.EndElement) { - if (base.Depth == _state.Depth && _states != null && _states.Count > 0) + if (base.Depth == _state.Depth && _states != null && _states.Count > 0) { //Pop previous state _state = _states.Pop(); } } } - return baseRead; + return baseRead; } #endregion } - internal class XmlBaseState + internal class XmlBaseState { - public XmlBaseState() {} + public XmlBaseState() { } - public XmlBaseState(Uri baseUri, int depth) + public XmlBaseState(Uri baseUri, int depth) { this.BaseUri = baseUri; this.Depth = depth; Index: XmlNamespaces.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/XmlNamespaces.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XmlNamespaces.cs 16 Oct 2005 16:51:24 -0000 1.1 +++ XmlNamespaces.cs 25 Oct 2005 21:33:43 -0000 1.2 @@ -10,13 +10,8 @@ /// Provides public constants for wellknown XML namespaces. /// </summary> /// <remarks>Author: Daniel Cazzulino, kz...@gm...</remarks> - public sealed class XmlNamespaces - { - #region Ctor - - private XmlNamespaces() {} - - #endregion Ctor + public static class XmlNamespaces + { #region Public Constants |