//
-// System.Xml.XmlAttribute
+// System.Xml.XmlElement
//
// Author:
// Jason Diamond (jason@injektilo.org)
+// Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
//
// (C) 2002 Jason Diamond http://injektilo.org/
+// (C) 2002 Atsushi Enomoto
//
using System;
using System.Collections;
+using System.Xml.XPath;
+using System.IO;
+using System.Text;
namespace System.Xml
{
#region Fields
private XmlAttributeCollection attributes;
- private XmlLinkedNode lastLinkedChild;
private string localName;
private string namespaceURI;
private string prefix;
+ private bool isEmpty;
#endregion
this.namespaceURI = namespaceURI;
attributes = new XmlAttributeCollection (this);
+
+ // TODO: Adds default attributes
+ if(doc.DocumentType != null)
+ {
+ }
}
#endregion
get { return attributes.Count > 0; }
}
- [MonoTODO ("Setter.")]
+ public override string InnerText {
+ get {
+ return base.InnerText;
+ }
+ set {
+ foreach(XmlNode n in ChildNodes)
+ {
+ this.RemoveChild(n);
+ }
+ // creates new Text node
+ AppendChild(OwnerDocument.CreateTextNode(value));
+ }
+ }
+
+ [MonoTODO ("Setter is immature")]
public override string InnerXml {
get {
// Not sure why this is an override. Passing through for now.
return base.InnerXml;
}
- set { throw new NotImplementedException (); }
+ set {
+ foreach(XmlNode n in ChildNodes)
+ {
+ this.RemoveChild(n);
+ }
+
+ // I hope there are any well-performance logic...
+ XmlNameTable nt = this.OwnerDocument.NameTable;
+ XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
+ XmlParserContext ctx = new XmlParserContext (nt, nsmgr, XmlLang, this.XmlSpace);
+ XmlTextReader xmlReader = OwnerDocument.ReusableReader;
+ xmlReader.SetReaderContext (String.Empty, ctx);
+ xmlReader.SetReaderFragment (new StringReader (value), XmlNodeType.Element);
+ this.ConstructDOM (xmlReader, this);
+ }
}
- [MonoTODO]
public bool IsEmpty {
- get { throw new NotImplementedException (); }
+ get { return isEmpty; }
- set { throw new NotImplementedException (); }
+ set {
+ if(value) {
+ RemoveAll();
+ }
+ isEmpty = value;
+ }
}
- internal override XmlLinkedNode LastLinkedChild {
- get { return lastLinkedChild; }
-
- set { lastLinkedChild = value; }
- }
-
public override string LocalName {
get { return localName; }
}
}
}
+ internal override XPathNodeType XPathNodeType {
+ get {
+ return XPathNodeType.Element;
+ }
+ }
+
[MonoTODO]
public override XmlDocument OwnerDocument {
get {
}
public override string Prefix {
- get {
- return prefix;
- }
+ get { return prefix; }
+ set { prefix = value; }
}
#endregion
public virtual XmlNodeList GetElementsByTagName (string name)
{
ArrayList nodeArrayList = new ArrayList ();
- this.searchNodesRecursively (this, name, String.Empty, nodeArrayList);
+ this.searchNodesRecursively (this, name, nodeArrayList);
return new XmlNodeArrayList (nodeArrayList);
}
+ private void searchNodesRecursively (XmlNode argNode, string argName,
+ ArrayList argArrayList)
+ {
+ XmlNodeList xmlNodeList = argNode.ChildNodes;
+ foreach (XmlNode node in xmlNodeList){
+ if (node.Name.Equals (argName))
+ argArrayList.Add (node);
+ else
+ this.searchNodesRecursively (node, argName, argArrayList);
+ }
+ }
+
private void searchNodesRecursively (XmlNode argNode, string argName, string argNamespaceURI,
ArrayList argArrayList)
{
[MonoTODO]
public virtual bool HasAttribute (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI);
+ return attributeNode != null;
}
- [MonoTODO ("Don't remove default attributes.")]
+ [MonoTODO ("confirm not removing default attributes [when DTD feature was implemented.")]
public override void RemoveAll ()
{
// Remove the child nodes.
attributes.RemoveAll ();
}
- [MonoTODO]
+ [MonoTODO ("confirm not removing default attributes [when DTD feature was implemented.")]
public virtual void RemoveAllAttributes ()
{
- throw new NotImplementedException ();
+ attributes.RemoveAll ();
}
- [MonoTODO]
+ [MonoTODO ("confirm not resetting default attributes [when DTD feature was implemented.")]
public virtual void RemoveAttribute (string name)
{
- throw new NotImplementedException ();
+ attributes.Remove((XmlAttribute)attributes.GetNamedItem(name));
}
- [MonoTODO]
+ [MonoTODO ("confirm not resetting default attributes [when DTD feature was implemented.")]
public virtual void RemoveAttribute (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ attributes.Remove((XmlAttribute)attributes.GetNamedItem(localName, namespaceURI));
}
- [MonoTODO]
+ [MonoTODO ("confirm not resetting default attributes [when DTD feature was implemented.")]
public virtual XmlNode RemoveAttributeAt (int i)
{
- throw new NotImplementedException ();
+ return attributes.Remove(attributes[i]);
}
- [MonoTODO]
+ [MonoTODO ("confirm not resetting default attributes [when DTD feature was implemented.")]
public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr)
{
- throw new NotImplementedException ();
+ return attributes.Remove(oldAttr);
}
- [MonoTODO]
+ [MonoTODO ("confirm not resetting default attributes [when DTD feature was implemented.")]
public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ return attributes.Remove(attributes[localName, namespaceURI]);
}
[MonoTODO]
public virtual void SetAttribute (string name, string value)
{
XmlAttribute attribute = OwnerDocument.CreateAttribute (name);
- attribute.SetParentNode (this);
+ attribute.SetOwnerElement(this);
attribute.Value = value;
Attributes.SetNamedItem (attribute);
}
- [MonoTODO]
+// [MonoTODO]
public virtual string SetAttribute (string localName, string namespaceURI, string value)
{
- throw new NotImplementedException ();
+ XmlAttribute attr = attributes[localName, namespaceURI];
+ if(attr == null)
+ {
+ attr = OwnerDocument.CreateAttribute(localName, namespaceURI);
+ attr.Value = value;
+ attributes.SetNamedItem(attr);
+ }
+ else
+ attr.Value = value;
+ return attr.Value;
}
- [MonoTODO]
+// [MonoTODO]
public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr)
{
- newAttr.SetParentNode(this);
+ newAttr.SetOwnerElement(this);
XmlNode oldAttr = Attributes.SetNamedItem(newAttr);
return oldAttr != null ? oldAttr as XmlAttribute : null;
}
- [MonoTODO]
public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
{
- throw new NotImplementedException ();
+ XmlDocument xmlDoc = this.OwnerDocument;
+ XmlAttribute xmlAttribute = new XmlAttribute (String.Empty, localName, namespaceURI, xmlDoc);
+ return this.attributes.Append (xmlAttribute);
}
public override void WriteContentTo (XmlWriter w)
childNode.WriteTo(w);
}
+ [MonoTODO("indenting feature is incomplete.")]
public override void WriteTo (XmlWriter w)
{
w.WriteStartElement(Prefix, LocalName, NamespaceURI);
+ // write namespace declarations(if not exist)
+ if(Prefix != null && Prefix != String.Empty && w.LookupPrefix(Prefix) != NamespaceURI)
+ w.WriteAttributeString("xmlns", Prefix, "http://www.w3.org/2000/xmlns/", NamespaceURI);
+
foreach(XmlNode attributeNode in Attributes)
+ {
attributeNode.WriteTo(w);
+ // write namespace declarations(if not exist)
+ if(attributeNode.Prefix != null && attributeNode.Prefix != String.Empty &&
+ w.LookupPrefix(attributeNode.Prefix) != attributeNode.NamespaceURI &&
+ attributeNode.Prefix != "xmlns")
+ w.WriteAttributeString("xmlns", attributeNode.Prefix, "http://www.w3.org/2000/xmlns/", attributeNode.NamespaceURI);
+ }
WriteContentTo(w);