[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlEntityReference.cs,NONE
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlEntityReference.cs,NONE,1.1 XmlProcessingInstruction.cs,NONE,1.1 XmlDocument.cs,1.3,1.4 XmlElement.cs,1.2,1.3 |
Date: |
Wed, 04 Dec 2002 01:26:02 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Xml
In directory subversions:/tmp/cvs-serv2701/System.Xml
Modified Files:
XmlDocument.cs XmlElement.cs
Added Files:
XmlEntityReference.cs XmlProcessingInstruction.cs
Log Message:
Implement many of the DOM node types in the "System.Xml" namespace.
--- NEW FILE ---
/*
* XmlEntityReference.cs - Implementation of the
* "System.Xml.XmlEntityReference" 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
{
using System;
#if ECMA_COMPAT
internal
#else
public
#endif
class XmlEntityReference : XmlLinkedNode
{
// Internal state.
private String name;
// Constructor.
internal XmlEntityReference(XmlNode parent, String name)
: base(parent)
{
this.name = name;
}
// Get the base URI for this node.
public override String BaseURI
{
get
{
return base.BaseURI;
}
}
// Determine if this entity reference is read-only.
public override bool IsReadOnly
{
get
{
return true;
}
}
// Get the local name associated with this node.
public override String LocalName
{
get
{
return name;
}
}
// Get the name associated with this node.
public override String Name
{
get
{
return name;
}
}
// Get the type that is associated with this node.
public override XmlNodeType NodeType
{
get
{
return XmlNodeType.EntityReference;
}
}
// Get or set the value associated with this node.
public override String Value
{
get
{
return null;
}
set
{
throw new
InvalidOperationException(S._("Xml_ReadOnly"));
}
}
// Clone this node in either shallow or deep mode.
public override XmlNode CloneNode(bool deep)
{
return
OwnerDocument.CreateEntityReference(name);
}
// Writes the contents of this node to a specified XmlWriter.
public override void WriteContentTo(XmlWriter w)
{
foreach(XmlNode node in this)
{
node.WriteTo(w);
}
}
// Write this node and all of its contents to a specified XmlWriter.
public override void WriteTo(XmlWriter w)
{
w.WriteEntityRef(name);
}
}; // class XmlElement
}; // namespace System.Xml
--- NEW FILE ---
/*
* XmlProcessingInstruction.cs - Implementation of the
* "System.Xml.XmlProcessingInstruction" 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
{
using System;
#if ECMA_COMPAT
internal
#else
public
#endif
class XmlProcessingInstruction : XmlLinkedNode
{
// Internal state.
private String target;
private String data;
// Constructor.
internal XmlProcessingInstruction(XmlNode parent, String target,
String data)
: base(parent)
{
this.target = ((target != null) ? target :
String.Empty);
this.data = data;
}
// Get or set the data associated with a processing instruction.
public String Data
{
get
{
return data;
}
set
{
// TODO: change events
data = value;
}
}
// Get or set the inner text associated with this processing
instruction.
public override String InnerText
{
get
{
// TODO
return null;
}
set
{
// TODO
}
}
// Get the local name associated with this node.
public override String LocalName
{
get
{
return target;
}
}
// Get the name associated with this node.
public override String Name
{
get
{
return target;
}
}
// Get the type that is associated with this node.
public override XmlNodeType NodeType
{
get
{
return
XmlNodeType.ProcessingInstruction;
}
}
// Get the target associated with this processing instruction.
public String Target
{
get
{
return target;
}
}
// Get or set the value associated with this node.
public override String Value
{
get
{
return Data;
}
set
{
Data = value;
}
}
// Clone this node in either shallow or deep mode.
public override XmlNode CloneNode(bool deep)
{
return
OwnerDocument.CreateProcessingInstruction(target, data);
}
// Writes the contents of this node to a specified XmlWriter.
public override void WriteContentTo(XmlWriter w)
{
// Nothing to do here for processing
instructions.
}
// Write this node and all of its contents to a specified XmlWriter.
public override void WriteTo(XmlWriter w)
{
w.WriteProcessingInstruction(target, data);
}
}; // class XmlProcessingInstruction
}; // namespace System.Xml
Index: XmlDocument.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlDocument.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** XmlDocument.cs 4 Dec 2002 04:46:35 -0000 1.3
--- XmlDocument.cs 4 Dec 2002 06:25:59 -0000 1.4
***************
*** 214,219 ****
public override XmlNode CloneNode(bool deep)
{
! // TODO
! return null;
}
--- 214,225 ----
public override XmlNode CloneNode(bool deep)
{
! XmlDocument doc =
Implementation.CreateDocument();
! doc.baseURI = baseURI;
! if(deep)
! {
! // Copy across the children.
! // TODO
! }
! return doc;
}
***************
*** 224,228 ****
if(colon == -1)
{
! return CreateAttribute(name,
String.Empty, String.Empty);
}
else
--- 230,234 ----
if(colon == -1)
{
! return CreateAttribute(String.Empty,
name, String.Empty);
}
else
***************
*** 232,240 ****
if(prefix == "xmlns")
{
! return
CreateAttribute(localName, prefix, xmlns);
}
else
{
! return
CreateAttribute(localName, prefix, String.Empty);
}
}
--- 238,246 ----
if(prefix == "xmlns")
{
! return CreateAttribute(prefix,
localName, xmlns);
}
else
{
! return CreateAttribute(prefix,
localName, String.Empty);
}
}
***************
*** 247,251 ****
{
return CreateAttribute
! (qualifiedName, String.Empty,
namespaceURI);
}
else
--- 253,257 ----
{
return CreateAttribute
! (String.Empty, qualifiedName,
namespaceURI);
}
else
***************
*** 253,261 ****
String prefix =
qualifiedName.Substring(0, colon);
String localName =
qualifiedName.Substring(colon + 1);
! return CreateAttribute(localName,
prefix, namespaceURI);
}
}
public virtual XmlAttribute CreateAttribute
! (String localName, String prefix, String
namespaceURI)
{
if(prefix == "xmlns" && namespaceURI != xmlns)
--- 259,267 ----
String prefix =
qualifiedName.Substring(0, colon);
String localName =
qualifiedName.Substring(colon + 1);
! return CreateAttribute(prefix,
localName, namespaceURI);
}
}
public virtual XmlAttribute CreateAttribute
! (String prefix, String localName, String
namespaceURI)
{
if(prefix == "xmlns" && namespaceURI != xmlns)
***************
*** 294,297 ****
--- 300,554 ----
return new XmlDocumentType
(placeholder, name, publicId, systemId,
internalSubset);
+ }
+
+ // Create an element that is attached to this node.
+ public virtual XmlElement CreateElement(String name)
+ {
+ int colon = name.LastIndexOf(':');
+ if(colon == -1)
+ {
+ return CreateElement(String.Empty,
name, String.Empty);
+ }
+ else
+ {
+ String prefix = name.Substring(0,
colon);
+ String localName = name.Substring(colon
+ 1);
+ if(prefix == "xmlns")
+ {
+ return CreateElement(prefix,
localName, xmlns);
+ }
+ else
+ {
+ return CreateElement(prefix,
localName, String.Empty);
+ }
+ }
+ }
+ public virtual XmlElement CreateElement(String qualifiedName,
+
String namespaceURI)
+ {
+ int colon = qualifiedName.LastIndexOf(':');
+ if(colon == -1)
+ {
+ return CreateElement
+ (String.Empty, qualifiedName,
namespaceURI);
+ }
+ else
+ {
+ String prefix =
qualifiedName.Substring(0, colon);
+ String localName =
qualifiedName.Substring(colon + 1);
+ return CreateElement(prefix, localName,
namespaceURI);
+ }
+ }
+ public virtual XmlElement CreateElement(String prefix,
+
String localName,
+
String namespaceURI)
+ {
+ if(prefix == "xmlns" && namespaceURI != xmlns)
+ {
+ throw new ArgumentException
+
(S._("Xml_InvalidNamespaceURI"), "namespaceURI");
+ }
+ NameCache.NameInfo info =
+ nameCache.Add(localName, prefix,
namespaceURI);
+ return new XmlElement(placeholder, info);
+ }
+
+ // Create an entity reference and attach it to this node.
+ public virtual XmlEntityReference CreateEntityReference(String name)
+ {
+ return new XmlEntityReference(placeholder,
name);
+ }
+
+ // Create a node of a given dynamic type.
+ public virtual XmlNode CreateNode(String nodeTypeString,
+
String name,
+
String namespaceURI)
+ {
+ XmlNodeType type;
+ switch(nodeTypeString)
+ {
+ case "attribute":
+ {
+ type = XmlNodeType.Attribute;
+ }
+ break;
+
+ case "cdatasection":
+ {
+ type = XmlNodeType.CDATA;
+ }
+ break;
+
+ case "comment":
+ {
+ type = XmlNodeType.Comment;
+ }
+ break;
+
+ case "document":
+ {
+ type = XmlNodeType.Document;
+ }
+ break;
+
+ case "documentfragment":
+ {
+ type =
XmlNodeType.DocumentFragment;
+ }
+ break;
+
+ case "documenttype":
+ {
+ type = XmlNodeType.DocumentType;
+ }
+ break;
+
+ case "element":
+ {
+ type = XmlNodeType.Element;
+ }
+ break;
+
+ case "entityreference":
+ {
+ type =
XmlNodeType.EntityReference;
+ }
+ break;
+
+ case "processinginstruction":
+ {
+ type =
XmlNodeType.ProcessingInstruction;
+ }
+ break;
+
+ case "significantwhitespace":
+ {
+ type =
XmlNodeType.SignificantWhitespace;
+ }
+ break;
+
+ case "text":
+ {
+ type = XmlNodeType.Text;
+ }
+ break;
+
+ case "whitespace":
+ {
+ type = XmlNodeType.Whitespace;
+ }
+ break;
+
+ default:
+ {
+ throw new ArgumentException
+
(S._("Xml_InvalidNodeType"), "nodeTypeString");
+ }
+ // Not reached
+ }
+ return CreateNode(type, name, namespaceURI);
+ }
+ public virtual XmlNode CreateNode(XmlNodeType type,
+
String name,
+
String namespaceURI)
+ {
+ return CreateNode(type, null, name,
namespaceURI);
+ }
+ public virtual XmlNode CreateNode(XmlNodeType type,
+
String prefix, String name,
+
String namespaceURI)
+ {
+ switch(type)
+ {
+ case XmlNodeType.Element:
+ {
+ if(prefix == null)
+ return
CreateElement(name, namespaceURI);
+ else
+ return
CreateElement(prefix, name, namespaceURI);
+ }
+ // Not reached
+
+ case XmlNodeType.Attribute:
+ {
+ if(prefix == null)
+ return
CreateAttribute(name, namespaceURI);
+ else
+ return
CreateAttribute(prefix, name, namespaceURI);
+ }
+ // Not reached
+
+ case XmlNodeType.Text:
+ {
+ return
CreateTextNode(String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.CDATA:
+ {
+ return
CreateCDataSection(String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.EntityReference:
+ {
+ // TODO
+ return
CreateEntityReference(name);
+ }
+ // Not reached
+
+ case XmlNodeType.ProcessingInstruction:
+ {
+ // TODO
+ return
CreateProcessingInstruction(name, String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.Comment:
+ {
+ return
CreateComment(String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.Document:
+ {
+ return new XmlDocument();
+ }
+ // Not reached
+
+ case XmlNodeType.DocumentType:
+ {
+ return CreateDocumentType(name,
String.Empty,
+
String.Empty, String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.DocumentFragment:
+ {
+ return CreateDocumentFragment();
+ }
+ // Not reached
+
+ case XmlNodeType.Whitespace:
+ {
+ return
CreateWhitespace(String.Empty);
+ }
+ // Not reached
+
+ case XmlNodeType.SignificantWhitespace:
+ {
+ return
CreateSignificantWhitespace(String.Empty);
+ }
+ // Not reached
+ }
+ throw new ArgumentOutOfRangeException
+ ("type", S._("Xml_InvalidNodeType"));
+ }
+
+ // Create a processing instruction node.
+ public virtual XmlProcessingInstruction CreateProcessingInstruction
+ (String target, String data)
+ {
+ return new
XmlProcessingInstruction(placeholder, target, data);
}
Index: XmlElement.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Xml/XmlElement.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** XmlElement.cs 4 Dec 2002 04:46:35 -0000 1.2
--- XmlElement.cs 4 Dec 2002 06:25:59 -0000 1.3
***************
*** 32,60 ****
{
// Internal state.
! private String prefix;
! private String localName;
! private String ns;
! private String name;
private XmlAttributeCollection attributes;
private bool isEmpty;
// Constructor.
! internal XmlElement(XmlNode owner, String prefix,
! String localName, String ns)
! : base(owner)
! {
! this.prefix = prefix;
! this.localName =
! ((localName != null) ? localName :
String.Empty);
! this.ns = ((ns != null) ? ns : String.Empty);
! if(prefix != null)
! {
! name = prefix + ":" + localName;
! }
! else
! {
! name = localName;
! prefix = String.Empty;
! }
this.attributes = new
XmlAttributeCollection(this);
this.isEmpty = true;
--- 32,44 ----
{
// Internal state.
! private NameCache.NameInfo name;
private XmlAttributeCollection attributes;
private bool isEmpty;
// Constructor.
! internal XmlElement(XmlNode parent, NameCache.NameInfo name)
! : base(parent)
! {
! this.name = name;
this.attributes = new
XmlAttributeCollection(this);
this.isEmpty = true;
***************
*** 125,129 ****
get
{
! return localName;
}
}
--- 109,113 ----
get
{
! return name.localName;
}
}
***************
*** 134,138 ****
get
{
! return name;
}
}
--- 118,122 ----
get
{
! return name.name;
}
}
***************
*** 143,147 ****
get
{
! return ns;
}
}
--- 127,131 ----
get
{
! return name.ns;
}
}
***************
*** 196,200 ****
get
{
! return prefix;
}
}
--- 180,184 ----
get
{
! return name.prefix;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Xml XmlEntityReference.cs,NONE,1.1 XmlProcessingInstruction.cs,NONE,1.1 XmlDocument.cs,1.3,1.4 XmlElement.cs,1.2,1.3,
Rhys Weatherley <address@hidden> <=