2 // System.Xml.XmlAttribute
5 // Jason Diamond (jason@injektilo.org)
7 // (C) 2002 Jason Diamond http://injektilo.org/
12 using System.Xml.XPath;
16 public class XmlAttribute : XmlNode
20 private XmlLinkedNode lastChild;
21 private string localName;
22 private string namespaceURI;
23 private string prefix;
24 internal bool isDefault;
25 private XmlElement ownerElement;
31 [MonoTODO("need to set namespaceURI if prefix is recognized built-in ones like xmlns")]
32 protected internal XmlAttribute (
36 XmlDocument doc) : base (doc)
38 // What to be recognized is: xml:space, xml:lang, xml:base, and
39 // xmlns and xmlns:* (when XmlDocument.Namespaces = true only)
41 this.localName = localName;
42 this.namespaceURI = namespaceURI;
49 public override string BaseURI {
51 return OwnerElement.BaseURI;
55 public override string InnerText {
57 StringBuilder builder = new StringBuilder ();
58 AppendChildValues (this, builder);
59 return builder.ToString ();
67 private void AppendChildValues (XmlNode parent, StringBuilder builder)
69 XmlNode node = parent.FirstChild;
71 while (node != null) {
72 builder.Append (node.Value);
73 AppendChildValues (node, builder);
74 node = node.NextSibling;
78 [MonoTODO ("Setter is incomplete(XmlTextReader.ReadAttribute is incomplete;No resolution for xml:lang/space")]
79 public override string InnerXml {
81 // Not sure why this is an override. Passing through for now.
86 XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
87 XmlParserContext ctx = new XmlParserContext (OwnerDocument.NameTable, nsmgr, String.Empty, XmlSpace.Default);
88 XmlTextReader xtr = new XmlTextReader ("'" + value.Replace ("'", "'") + "'", XmlNodeType.Attribute, ctx);
89 xtr.ReadAttributeValue ();
94 public override string LocalName {
100 public override string Name {
102 return prefix != String.Empty ? prefix + ":" + localName : localName;
106 public override string NamespaceURI {
112 public override XmlNodeType NodeType {
114 return XmlNodeType.Attribute;
118 internal override XPathNodeType XPathNodeType {
120 return XPathNodeType.Attribute;
124 public override XmlDocument OwnerDocument {
126 return base.OwnerDocument;
130 public virtual XmlElement OwnerElement {
136 public override XmlNode ParentNode {
138 // It always returns null (by specification).
143 [MonoTODO("setter incomplete (name character check, format check, wrong prefix&nsURI)")]
144 // We gotta do more in the set block here
145 // We need to do the proper tests and throw
146 // the correct Exceptions
148 // Wrong cases are: (1)check readonly, (2)check character validity,
149 // (3)check format validity, (4)this is attribute and qualifiedName != "xmlns"
150 // (5)when argument is 'xml' or 'xmlns' and namespaceURI doesn't match
151 public override string Prefix {
154 throw new XmlException ("This node is readonly.");
156 XmlNamespaceManager nsmgr = ConstructNamespaceManager ();
157 string nsuri = nsmgr.LookupNamespace (value);
159 throw new XmlException ("Namespace URI not found for this prefix");
169 [MonoTODO("There are no code which sets 'specified = true', so this logic is without checking.")]
170 public virtual bool Specified {
176 public override string Value {
178 XmlNode firstChild = FirstChild;
179 if (firstChild == null)
181 return firstChild.Value;
185 XmlNode firstChild = FirstChild;
186 if (firstChild == null)
187 AppendChild (OwnerDocument.CreateTextNode (value));
189 firstChild.Value = value;
197 public override XmlNode CloneNode (bool deep)
199 XmlNode node = new XmlAttribute (prefix, localName, namespaceURI,
202 while ((node != null) && (node.HasChildNodes)) {
203 AppendChild (node.NextSibling.CloneNode (true));
204 node = node.NextSibling;
211 // Parent of XmlAttribute must be null
212 internal void SetOwnerElement (XmlElement el) {
216 public override void WriteContentTo (XmlWriter w)
218 w.WriteString (Value);
221 public override void WriteTo (XmlWriter w)
223 w.WriteAttributeString (prefix, localName, namespaceURI, Value);
228 internal override XmlLinkedNode LastLinkedChild {
229 get { return lastChild; }
231 set { lastChild = value; }