| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- //
- // System.Xml.XmlAttribute
- //
- // Author:
- // Jason Diamond ([email protected])
- //
- // (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 InnerXml {
- get {
- // Not sure why this is an override. Passing through for now.
- return base.InnerXml;
- }
- set { throw new NotImplementedException (); }
- }
- [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;
- }
- }
- #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);
- }
- }
- [MonoTODO]
- public virtual XmlNodeList GetElementsByTagName (string localName, string namespaceURI)
- {
- throw new NotImplementedException ();
- }
- [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 ();
- }
- [MonoTODO]
- public virtual void RemoveAllAttributes ()
- {
- throw new NotImplementedException ();
- }
- [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;
- }
- [MonoTODO]
- public virtual XmlAttribute SetAttributeNode (string localName, string namespaceURI)
- {
- throw new NotImplementedException ();
- }
- 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
- }
- }
|