[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlValidatingReader.cs,NON
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlValidatingReader.cs,NONE,1.1 Xml.build,1.4,1.5 XmlNode.cs,1.5,1.6 XmlTextReader.cs,1.6,1.7 XmlTextWriter.cs,1.2,1.3 |
Date: |
Mon, 02 Dec 2002 18:55:46 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv16146/System.Xml
Modified Files:
Xml.build XmlNode.cs XmlTextReader.cs XmlTextWriter.cs
Added Files:
XmlValidatingReader.cs
Log Message:
Some test cases for XmlTextWriter; build the skeleton for XmlTextReader;
implementing XmlValidatingReader as a non-validating wrapper around
XmlTextReader.
--- NEW FILE ---
/*
* XmlValidatingReader.cs - Implementation of the
* "System.Xml.XmlValidatingReader" class.
*
* Copyright (C) 2002 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Xml
{
#if !ECMA_COMPAT
using System;
using System.IO;
using System.Text;
// Note: this class doesn't actually do any validation yet. It acts as
// a pass-through to "XmlTextReader" to fake out applications that ask
// for a validating reader when a non-validating one will normally do.
// Patches are welcome to make this really do validation.
public class XmlValidatingReader : XmlReader, IXmlLineInfo
{
// Internal state.
private XmlTextReader reader;
private EntityHandling entityHandling;
private ValidationType validationType;
// Constructors.
public XmlValidatingReader(XmlReader reader)
{
this.reader = (reader as XmlTextReader);
if(this.reader == null)
{
throw new ArgumentException
(S._("Xml_NotTextReader"),
"reader");
}
entityHandling = EntityHandling.ExpandEntities;
validationType = ValidationType.Auto;
}
public XmlValidatingReader(Stream xmlFragment, XmlNodeType fragType,
XmlParserContext
context)
{
reader = new XmlTextReader(xmlFragment,
fragType, context);
entityHandling = EntityHandling.ExpandEntities;
validationType = ValidationType.Auto;
}
public XmlValidatingReader(String xmlFragment, XmlNodeType fragType,
XmlParserContext
context)
{
reader = new XmlTextReader(xmlFragment,
fragType, context);
entityHandling = EntityHandling.ExpandEntities;
validationType = ValidationType.Auto;
}
// Clean up the resources that were used by this XML reader.
public override void Close()
{
reader.Close();
}
// Returns the value of an attribute with a specific index.
public override String GetAttribute(int i)
{
return reader.GetAttribute(i);
}
// Returns the value of an attribute with a specific name.
public override String GetAttribute(String name, String namespaceURI)
{
return reader.GetAttribute(name, namespaceURI);
}
// Returns the value of an attribute with a specific qualified name.
public override String GetAttribute(String name)
{
return reader.GetAttribute(name);
}
// Resolve a namespace in the scope of the current element.
public override String LookupNamespace(String prefix)
{
return reader.LookupNamespace(prefix);
}
// Move the current position to a particular attribute.
public override void MoveToAttribute(int i)
{
reader.MoveToAttribute(i);
}
// Move the current position to an attribute with a particular name.
public override bool MoveToAttribute(String name, String ns)
{
return reader.MoveToAttribute(name, ns);
}
// Move the current position to an attribute with a qualified name.
public override bool MoveToAttribute(String name)
{
return reader.MoveToAttribute(name);
}
// Move to the element that owns the current attribute.
public override bool MoveToElement()
{
return reader.MoveToElement();
}
// Move to the first attribute owned by the current element.
public override bool MoveToFirstAttribute()
{
return reader.MoveToFirstAttribute();
}
// Move to the next attribute owned by the current element.
public override bool MoveToNextAttribute()
{
return reader.MoveToNextAttribute();
}
// Read the next node in the input stream.
public override bool Read()
{
return reader.Read();
}
// Read the next attribute value in the input stream.
public override bool ReadAttributeValue()
{
return reader.ReadAttributeValue();
}
// Read the contents of the current node, including all markup.
public override String ReadInnerXml()
{
return reader.ReadInnerXml();
}
// Read the current node, including all markup.
public override String ReadOuterXml()
{
return reader.ReadOuterXml();
}
// Read the contents of an element or text node as a string.
public override String ReadString()
{
return reader.ReadString();
}
// Read a typed value.
[TODO]
public Object ReadTypedValue()
{
// TODO
return ReadString();
}
// Resolve an entity reference.
public override void ResolveEntity()
{
reader.ResolveEntity();
}
// Get the number of attributes on the current node.
public override int AttributeCount
{
get
{
return reader.AttributeCount;
}
}
// Get the base URI for the current node.
public override String BaseURI
{
get
{
return reader.BaseURI;
}
}
// Determine if this reader can parse and resolve entities.
public override bool CanResolveEntity
{
get
{
return true;
}
}
// Get the depth of the current node.
public override int Depth
{
get
{
return reader.Depth;
}
}
// Determine if we have reached the end of the input stream.
public override bool EOF
{
get
{
return reader.EOF;
}
}
// Get the encoding that is in use by the XML stream.
public Encoding Encoding
{
get
{
return reader.Encoding;
}
}
// Get or set the entity handling mode.
public EntityHandling EntityHandling
{
get
{
return entityHandling;
}
set
{
if(value !=
EntityHandling.ExpandEntities &&
value !=
EntityHandling.ExpandCharEntities)
{
throw new
ArgumentOutOfRangeException
("value",
S._("Xml_InvalidEntityHandling"));
}
entityHandling = value;
}
}
// Determine if the current node can have an associated text value.
public override bool HasValue
{
get
{
return reader.HasValue;
}
}
// Determine if the current node's value was generated from a DTD
default.
public override bool IsDefault
{
get
{
return reader.IsDefault;
}
}
// Determine if the current node is an empty element.
public override bool IsEmptyElement
{
get
{
return reader.IsEmptyElement;
}
}
// Retrieve an attribute value with a specified index.
public override String this[int i]
{
get
{
return reader.GetAttribute(i);
}
}
// Retrieve an attribute value with a specified name.
public override String this[String localname, String namespaceURI]
{
get
{
return reader.GetAttribute(localname,
namespaceURI);
}
}
// Retrieve an attribute value with a specified qualified name.
public override String this[String name]
{
get
{
return reader.GetAttribute(name);
}
}
// Determine if we have line information.
bool IXmlLineInfo.HasLineInfo()
{
return ((IXmlLineInfo)reader).HasLineInfo();
}
// Get the current line number.
public int LineNumber
{
get
{
return reader.LineNumber;
}
}
// Get the current line position.
public int LinePosition
{
get
{
return reader.LinePosition;
}
}
// Get the local name of the current node.
public override String LocalName
{
get
{
return reader.LocalName;
}
}
// Get the fully-qualified name of the current node.
public override String Name
{
get
{
return reader.Name;
}
}
// Get the name that that is used to look up and resolve names.
public override XmlNameTable NameTable
{
get
{
return reader.NameTable;
}
}
// Get the namespace URI associated with the current node.
public override String NamespaceURI
{
get
{
return reader.NamespaceURI;
}
}
// Get or set the "namespace support" flag for this reader.
public bool Namespaces
{
get
{
return reader.Namespaces;
}
set
{
reader.Namespaces = value;
}
}
// Get or set the "normalize" flag for this reader.
public bool Normalization
{
get
{
return reader.Normalization;
}
set
{
reader.Normalization = value;
}
}
// Get the type of the current node.
public override XmlNodeType NodeType
{
get
{
return reader.NodeType;
}
}
// Get the namespace prefix associated with the current node.
public override String Prefix
{
get
{
return reader.Prefix;
}
}
// Get the quote character that was used to enclose an attribute value.
public override char QuoteChar
{
get
{
return reader.QuoteChar;
}
}
// Get the reader underlying this validating reader.
public XmlReader Reader
{
get
{
return reader;
}
}
// Get the current read state of the reader.
public override ReadState ReadState
{
get
{
return reader.ReadState;
}
}
#if false
// Get the schemas that are being used to validate.
[TODO]
public XmlSchemaCollection Schemas
{
get
{
// TODO
return null;
}
}
#endif
// Get the schema type for the current node.
[TODO]
public Object SchemaType
{
get
{
// TODO
return null;
}
}
// Get or set the validation type.
public ValidationType ValidationType
{
get
{
return validationType;
}
set
{
if(value < ValidationType.None ||
value > ValidationType.Schema)
{
throw new
ArgumentOutOfRangeException
("value",
S._("Xml_InvalidValidationType"));
}
validationType = value;
}
}
// Get the text value of the current node.
public override String Value
{
get
{
return reader.Value;
}
}
// Get the current xml:lang scope.
public override String XmlLang
{
get
{
return reader.XmlLang;
}
}
// Set the resolver to use to resolve DTD references.
public XmlResolver XmlResolver
{
set
{
reader.XmlResolver = value;
}
}
// Get the current xml:space scope.
public override XmlSpace XmlSpace
{
get
{
return reader.XmlSpace;
}
}
}; // class XmlValidatingReader
#endif // !ECMA_COMPAT
}; // namespace System.Xml
Index: Xml.build
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/Xml.build,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Xml.build 26 Jul 2002 11:51:37 -0000 1.4
--- Xml.build 2 Dec 2002 23:55:43 -0000 1.5
***************
*** 8,11 ****
--- 8,12 ----
unsafe="true"
nostdlib="true"
+ debug="true"
optimize="true">
Index: XmlNode.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlNode.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** XmlNode.cs 27 Jul 2002 09:42:59 -0000 1.5
--- XmlNode.cs 2 Dec 2002 23:55:43 -0000 1.6
***************
*** 421,461 ****
public abstract void WriteTo(XmlWriter w);
- #if false
- public XmlNode Parent = null; //Pointer to the parent node, NULL if no
parent
- public XmlNode Prev = null; //Pointer to the previous node, NULL if no
previous
- public XmlNode Next = null; //Pointer to the next node, NULL if no next
- public ArrayList Children = null; //Pointer to the child nodes, NULL if
no children
-
- public XmlNodeType Type; //The type of this node
- public String Text; //The text of this node,
- //for example the name of an
element node
- public int Depth = -1; //The Depth of the current node, 0 is the top
layer,
- //1 the layer under top,
etc. -1 Is error.
-
-
- public XmlNode(XmlNode prev, XmlNode up, XmlNodeType type, String text,
int depth)
- {
- if (prev != null)
- {
- prev.Next = this;
- this.Prev = prev;
- }
-
- if (up != null)
- {
- this.Parent = up;
- if(up.Children == null)
- {
- up.Children = new ArrayList();
- }
- up.Children.Add(this);
- }
-
- this.Type = type;
- this.Text = text;
- this.Depth = depth;
- }
- #endif
-
}; // class XmlNode
--- 421,424 ----
Index: XmlTextReader.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextReader.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** XmlTextReader.cs 27 Jul 2002 09:42:59 -0000 1.6
--- XmlTextReader.cs 2 Dec 2002 23:55:43 -0000 1.7
***************
*** 23,940 ****
using System;
- using System.Collections;
using System.IO;
using System.Text;
- // This class reads and parses a complete xml file into memory, the
- // methods called on it return data from the parses memory file.
- // This is a simple however memory inefficient use, but the efficiency
- // of parsing should improve.
[...1566 lines suppressed...]
!
! // Set the resolver to use to resolve DTD references.
! public XmlResolver XmlResolver
! {
! set
! {
! xmlResolver = value;
! }
! }
!
! // Get the current xml:space scope.
! public override XmlSpace XmlSpace
! {
! get
! {
! return xmlSpace;
! }
! }
}; // class XmlTextReader
Index: XmlTextWriter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlTextWriter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** XmlTextWriter.cs 2 Dec 2002 06:36:36 -0000 1.2
--- XmlTextWriter.cs 2 Dec 2002 23:55:43 -0000 1.3
***************
*** 90,94 ****
scope = null;
indentLevel = 0;
! xmlSpace = XmlSpace.Default;
xmlLang = null;
pseudoNSNumber = 1;
--- 90,94 ----
scope = null;
indentLevel = 0;
! xmlSpace = XmlSpace.None;
xmlLang = null;
pseudoNSNumber = 1;
***************
*** 101,106 ****
{
scope = new ElementScope(scope);
! scope.prefix = nameTable.Add(prefix);
! scope.localName = nameTable.Add(localName);
scope.scopeShown = scopeShown;
if(formatting == System.Xml.Formatting.Indented)
--- 101,107 ----
{
scope = new ElementScope(scope);
! scope.prefix = (prefix != null ?
nameTable.Add(prefix) : null);
! scope.localName =
! (localName != null ?
nameTable.Add(localName) : null);
scope.scopeShown = scopeShown;
if(formatting == System.Xml.Formatting.Indented)
***************
*** 515,534 ****
}
- // Pretend that we are in attribute mode so that
- // "WriteString" will apply the correct quoting.
- writeState = System.Xml.WriteState.Attribute;
-
// Write out the document type information.
writer.Write("<!DOCTYPE ");
writer.Write(name);
writer.Write(" PUBLIC \"");
! WriteString(pubid);
writer.Write("\" \"");
! WriteString(sysid);
writer.Write('\"');
if(subset != null && subset.Length != 0)
{
writer.Write(" \"");
! WriteString(subset);
writer.Write('\"');
}
--- 516,531 ----
}
// Write out the document type information.
writer.Write("<!DOCTYPE ");
writer.Write(name);
writer.Write(" PUBLIC \"");
! WriteQuotedString(pubid);
writer.Write("\" \"");
! WriteQuotedString(sysid);
writer.Write('\"');
if(subset != null && subset.Length != 0)
{
writer.Write(" \"");
! WriteQuotedString(subset);
writer.Write('\"');
}
***************
*** 569,572 ****
--- 566,570 ----
{
// Terminate the attribute and the
element start.
+ Console.WriteLine("hello");
writer.Write(quoteChar);
writer.Write(" />");
***************
*** 582,585 ****
--- 580,587 ----
writer.Write(" />");
PopScope();
+ if(xmlSpace !=
System.Xml.XmlSpace.Preserve)
+ {
+ writer.WriteLine();
+ }
}
while(scope != null)
***************
*** 790,794 ****
writer.Write('=');
writer.Write(quoteChar);
! WriteString(ns);
writer.Write(quoteChar);
writer.Write(' ');
--- 792,796 ----
writer.Write('=');
writer.Write(quoteChar);
! WriteQuotedString(ns);
writer.Write(quoteChar);
writer.Write(' ');
***************
*** 818,822 ****
writer.Write('=');
writer.Write(quoteChar);
! WriteString(ns);
writer.Write(quoteChar);
writer.Write(' ');
--- 820,824 ----
writer.Write('=');
writer.Write(quoteChar);
! WriteQuotedString(ns);
writer.Write(quoteChar);
writer.Write(' ');
***************
*** 907,919 ****
// We need to be in the Element or Content
state.
! if(writeState == System.Xml.WriteState.Element)
! {
! writer.Write('>');
! }
! else if(writeState !=
System.Xml.WriteState.Content)
! {
! throw new InvalidOperationException
! (S._("Xml_InvalidWriteState"));
! }
// Get the current scope prefix.
--- 909,916 ----
// We need to be in the Element or Content
state.
! Sync(WriteStateFlag.ElementFlag |
! WriteStateFlag.AttributeFlag |
! WriteStateFlag.ContentFlag |
! WriteStateFlag.PrologFlag);
// Get the current scope prefix.
***************
*** 962,966 ****
writer.Write('=');
writer.Write(quoteChar);
! WriteString(ns);
writer.Write(quoteChar);
scopeShown = true;
--- 959,963 ----
writer.Write('=');
writer.Write(quoteChar);
! WriteQuotedString(ns);
writer.Write(quoteChar);
scopeShown = true;
***************
*** 994,998 ****
writer.Write('=');
writer.Write(quoteChar);
! WriteString(ns);
writer.Write(quoteChar);
scopeShown = true;
--- 991,995 ----
writer.Write('=');
writer.Write(quoteChar);
! WriteQuotedString(ns);
writer.Write(quoteChar);
scopeShown = true;
***************
*** 1025,1085 ****
}
! // We are now in the attribute state.
! writeState = System.Xml.WriteState.Attribute;
prevWasText = false;
}
! // Write a string.
! public override void WriteString(String text)
{
- // We must not be in the closed state.
- if(writeState == System.Xml.WriteState.Closed)
- {
- if(text != null && text.Length != 0)
- {
- throw new
InvalidOperationException
-
(S._("Xml_InvalidWriteState"));
- }
- return;
- }
-
- // If we are in the attribute state, then check
- // for the "xml:lang" and "xml:space"
attributes.
- if(writeState ==
System.Xml.WriteState.Attribute)
- {
- if(special == Special.Lang)
- {
- xmlLang = text;
- special = Special.None;
- }
- else if(special == Special.Space)
- {
- if(text == "default")
- {
- xmlSpace =
System.Xml.XmlSpace.Default;
- }
- else if(text == "preserve")
- {
- xmlSpace =
System.Xml.XmlSpace.Preserve;
- }
- else
- {
- xmlSpace =
System.Xml.XmlSpace.None;
- }
- special = Special.None;
- }
- }
-
- // If we are in the element state, then shift
to content.
- Sync(WriteStateFlag.ContentFlag |
- WriteStateFlag.AttributeFlag);
-
- // Bail out if the text is empty.
- if(((Object)text) == null || text.Length == 0)
- {
- return;
- }
-
- // Quote the string and output it.
int posn, prev, len;
char ch;
--- 1022,1033 ----
}
! // We are now in the element state.
! writeState = System.Xml.WriteState.Element;
prevWasText = false;
}
! // Write a quoted string.
! private void WriteQuotedString(String text)
{
int posn, prev, len;
char ch;
***************
*** 1183,1186 ****
--- 1131,1189 ----
}
+ // Write a string.
+ public override void WriteString(String text)
+ {
+ // We must not be in the closed state.
+ if(writeState == System.Xml.WriteState.Closed)
+ {
+ if(text != null && text.Length != 0)
+ {
+ throw new
InvalidOperationException
+
(S._("Xml_InvalidWriteState"));
+ }
+ return;
+ }
+
+ // If we are in the attribute state, then check
+ // for the "xml:lang" and "xml:space"
attributes.
+ if(writeState ==
System.Xml.WriteState.Attribute)
+ {
+ if(special == Special.Lang)
+ {
+ xmlLang = text;
+ special = Special.None;
+ }
+ else if(special == Special.Space)
+ {
+ if(text == "default")
+ {
+ xmlSpace =
System.Xml.XmlSpace.Default;
+ }
+ else if(text == "preserve")
+ {
+ xmlSpace =
System.Xml.XmlSpace.Preserve;
+ }
+ else
+ {
+ xmlSpace =
System.Xml.XmlSpace.None;
+ }
+ special = Special.None;
+ }
+ }
+
+ // If we are in the element state, then shift
to content.
+ Sync(WriteStateFlag.ContentFlag |
+ WriteStateFlag.AttributeFlag);
+
+ // Bail out if the text is empty.
+ if(((Object)text) == null || text.Length == 0)
+ {
+ return;
+ }
+
+ // Quote the string and output it.
+ WriteQuotedString(text);
+ }
+
// Write a surrogate character entity.
public override void WriteSurrogateCharEntity(char lowChar, char
highChar)
***************
*** 1299,1303 ****
(S._("Xml_InvalidWriteState"));
}
! namespaces = true;
}
}
--- 1302,1306 ----
(S._("Xml_InvalidWriteState"));
}
! namespaces = value;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlValidatingReader.cs,NONE,1.1 Xml.build,1.4,1.5 XmlNode.cs,1.5,1.6 XmlTextReader.cs,1.6,1.7 XmlTextWriter.cs,1.2,1.3,
Rhys Weatherley <address@hidden> <=