X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml%2FXmlElement.cs;h=4ccb1e7ba95a1003f5c8055e837089725a18649a;hb=3ffced165920cf94efc606d91ebcbe0d70c13aac;hp=b5af0ef78402932eb471f45617396e1bedaef4c7;hpb=04639cc5f046d3176208c63d3cdf88b33a139f5e;p=mono.git diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs index b5af0ef7840..4ccb1e7ba95 100644 --- a/mcs/class/System.XML/System.Xml/XmlElement.cs +++ b/mcs/class/System.XML/System.Xml/XmlElement.cs @@ -1,109 +1,336 @@ -// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- -// -// System.Xml.XmlElement -// -// Author: -// Daniel Weber (daniel-weber@austin.rr.com) -// -// (C) 2001 Daniel Weber -using System; - -namespace System.Xml -{ - public class XmlElement : XmlLinkedNode - { - // Private/Protected internal data structures - //=========================================================================== - private XmlAttributeCollection _attributes; - - // Public Properties - //=========================================================================== - - /// - /// Return the XmlAttributeCollection on the Element - /// - public override XmlAttributeCollection Attributes - { - get - { - // TODO - implement Attributes - return _attributes; - } - } - - - // Implement abstract methods of XmlNode - //===================================================================== - /// - /// Return a clone of the node - /// - /// Make copy of all children - /// Cloned node - public override XmlNode CloneNode( bool deep) - { - // TODO - implement CloneNode() - throw new NotImplementedException(); - } - - /// - /// Saves all children of the current node to the passed writer - /// - /// - public override void WriteContentTo(XmlWriter w) - { - // TODO - implement WriteContentsTo(XmlWriter) - throw new NotImplementedException(); - } - - /// - /// Saves the current node to writer w - /// - /// - public override void WriteTo(XmlWriter w) - { - // TODO - implement WriteTo(XmlWriter) - throw new NotImplementedException(); - } - - /// - /// Returns the local name of the node with qualifiers removed - /// LocalName of ns:elementName = "elementName" - /// - public override string LocalName - { - get - { - // TODO - implement LocalName - return String.Empty; - } - } - - - /// - /// Get the qualified node name - /// derived classes must implement as behavior varies - /// by tag type. - /// - public override string Name - { - get - { - // TODO - implement Name - return String.Empty; - } - } - - public override XmlNodeType NodeType - { - get - { - return XmlNodeType.Element; - } - } - - - // ============= Internal calls ============================================= - - - } // class - } //namespace +// +// System.Xml.XmlAttribute +// +// Author: +// Jason Diamond (jason@injektilo.org) +// +// (C) 2002 Jason Diamond http://injektilo.org/ +// + +using System; +using System.Collections; + +namespace System.Xml +{ + public class XmlElement : XmlLinkedNode + { + #region Fields + + private XmlAttributeCollection attributes; + private XmlLinkedNode lastLinkedChild; + private string localName; + private string namespaceURI; + private string prefix; + + #endregion + + #region Constructor + + protected internal XmlElement ( + string prefix, + string localName, + string namespaceURI, + XmlDocument doc) : base (doc) + { + this.prefix = prefix; + this.localName = localName; + this.namespaceURI = namespaceURI; + + attributes = new XmlAttributeCollection (this); + } + + #endregion + + #region Properties + + public override XmlAttributeCollection Attributes { + get { return attributes; } + } + + public virtual bool HasAttributes { + get { return attributes.Count > 0; } + } + + [MonoTODO ("Setter.")] + public override string InnerText { + get { + // Not sure why this is an override. Passing through for now. + return base.InnerText; + } + set { throw new NotImplementedException (); } + } + + [MonoTODO ("Setter is immature")] + public override string InnerXml { + get { + // Not sure why this is an override. Passing through for now. + return base.InnerXml; + } + set { + // How to get xml:lang and xml:space? Create logic as ConstructNamespaceManager()? + XmlNameTable nt = this.OwnerDocument.NameTable; + XmlNamespaceManager nsmgr = this.ConstructNamespaceManager(); //new XmlNamespaceManager(nt); + string lang = ""; + XmlSpace space = XmlSpace.Default; + + XmlParserContext ctx = new XmlParserContext(nt, nsmgr, lang, space); + XmlTextReader xmlReader = new XmlTextReader(value, this.NodeType, ctx); + this.ConstructDOM(xmlReader, this); + } + } + + [MonoTODO] + public bool IsEmpty { + get { throw new NotImplementedException (); } + + set { throw new NotImplementedException (); } + } + + internal override XmlLinkedNode LastLinkedChild { + get { return lastLinkedChild; } + + set { lastLinkedChild = value; } + } + + public override string LocalName { + get { return localName; } + } + + public override string Name { + get { + return prefix != String.Empty ? prefix + ":" + localName : localName; + } + } + + public override string NamespaceURI { + get { return namespaceURI; } + } + + [MonoTODO] + public override XmlNode NextSibling { + get { + return base.NextSibling; + } + } + + public override XmlNodeType NodeType { + get { + return XmlNodeType.Element; + } + } + + [MonoTODO] + public override XmlDocument OwnerDocument { + get { + return base.OwnerDocument; + } + } + + public override string Prefix { + get { return prefix; } + set { prefix = value; } + } + + #endregion + + #region Methods + + [MonoTODO] + public override XmlNode CloneNode (bool deep) + { + XmlNode node = new XmlElement (prefix, localName, namespaceURI, + OwnerDocument); + + for (int i = 0; i < node.Attributes.Count; i++) + node.AppendChild (node.Attributes [i].CloneNode (false)); + + if (deep) { + while ((node != null) && (node.HasChildNodes)) { + AppendChild (node.NextSibling.CloneNode (true)); + node = node.NextSibling; + } + } // shallow cloning + + // + // Reminder: Also look into Default attributes. + // + return node; + } + + [MonoTODO] + public virtual string GetAttribute (string name) + { + XmlNode attributeNode = Attributes.GetNamedItem (name); + return attributeNode != null ? attributeNode.Value : String.Empty; + } + + [MonoTODO] + public virtual string GetAttribute (string localName, string namespaceURI) + { + XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI); + return attributeNode != null ? attributeNode.Value : String.Empty; + } + + [MonoTODO] + public virtual XmlAttribute GetAttributeNode (string name) + { + XmlNode attributeNode = Attributes.GetNamedItem (name); + return attributeNode != null ? attributeNode as XmlAttribute : null; + } + + [MonoTODO] + public virtual XmlAttribute GetAttributeNode (string localName, string namespaceURI) + { + XmlNode attributeNode = Attributes.GetNamedItem (localName, namespaceURI); + return attributeNode != null ? attributeNode as XmlAttribute : null; + } + + public virtual XmlNodeList GetElementsByTagName (string name) + { + ArrayList nodeArrayList = new ArrayList (); + 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) + { + XmlNodeList xmlNodeList = argNode.ChildNodes; + foreach (XmlNode node in xmlNodeList) + { + if (node.LocalName.Equals (argName) && node.NamespaceURI.Equals (argNamespaceURI)) + argArrayList.Add (node); + else + this.searchNodesRecursively (node, argName, argNamespaceURI, argArrayList); + } + } + + public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI) + { + ArrayList nodeArrayList = new ArrayList (); + this.searchNodesRecursively (this, localName, namespaceURI, nodeArrayList); + return new XmlNodeArrayList (nodeArrayList); + } + + [MonoTODO] + public virtual bool HasAttribute (string name) + { + XmlNode attributeNode = Attributes.GetNamedItem (name); + return attributeNode != null; + } + + [MonoTODO] + public virtual bool HasAttribute (string localName, string namespaceURI) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Don't remove default attributes.")] + public override void RemoveAll () + { + // Remove the child nodes. + base.RemoveAll (); + + // Remove all attributes. + attributes.RemoveAll (); + } + + public virtual void RemoveAllAttributes () + { + attributes.RemoveAll (); + } + + [MonoTODO] + public virtual void RemoveAttribute (string name) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual void RemoveAttribute (string localName, string namespaceURI) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual XmlNode RemoveAttributeAt (int i) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual XmlAttribute RemoveAttributeNode (XmlAttribute oldAttr) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual XmlAttribute RemoveAttributeNode (string localName, string namespaceURI) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual void SetAttribute (string name, string value) + { + XmlAttribute attribute = OwnerDocument.CreateAttribute (name); + attribute.SetParentNode (this); + attribute.Value = value; + Attributes.SetNamedItem (attribute); + } + + [MonoTODO] + public virtual string SetAttribute (string localName, string namespaceURI, string value) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public virtual XmlAttribute SetAttributeNode (XmlAttribute newAttr) + { + newAttr.SetParentNode(this); + XmlNode oldAttr = Attributes.SetNamedItem(newAttr); + return oldAttr != null ? oldAttr as XmlAttribute : null; + } + + + public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI) + { + XmlDocument xmlDoc = this.OwnerDocument; + XmlAttribute xmlAttribute = new XmlAttribute (String.Empty, localName, namespaceURI, xmlDoc); + return this.attributes.Append (xmlAttribute); + } + + public override void WriteContentTo (XmlWriter w) + { + foreach(XmlNode childNode in ChildNodes) + childNode.WriteTo(w); + } + + public override void WriteTo (XmlWriter w) + { + w.WriteStartElement(Prefix, LocalName, NamespaceURI); + + foreach(XmlNode attributeNode in Attributes) + attributeNode.WriteTo(w); + + WriteContentTo(w); + + w.WriteEndElement(); + } + + #endregion + } +}