1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using System.Collections.ObjectModel;
7
using System.Collections.Specialized;
8
using System.Diagnostics;
9
using System.Globalization;
12
using ICSharpCode.AvalonEdit.Document;
14
namespace ICSharpCode.AvalonEdit.Xml
17
/// Name-value pair in a tag
19
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
20
public class AXmlAttribute: AXmlObject
22
/// <summary> Name with namespace prefix - exactly as in source file </summary>
23
public string Name { get; internal set; }
24
/// <summary> Equals sign and surrounding whitespace </summary>
25
public string EqualsSign { get; internal set; }
26
/// <summary> The raw value - exactly as in source file (*probably* quoted and escaped) </summary>
27
public string QuotedValue { get; internal set; }
28
/// <summary> Unquoted and dereferenced value of the attribute </summary>
29
public string Value { get; internal set; }
31
internal override void DebugCheckConsistency(bool checkParentPointers)
33
DebugAssert(Name != null, "Null Name");
34
DebugAssert(EqualsSign != null, "Null EqualsSign");
35
DebugAssert(QuotedValue != null, "Null QuotedValue");
36
DebugAssert(Value != null, "Null Value");
37
base.DebugCheckConsistency(checkParentPointers);
40
#region Helpper methods
42
/// <summary> The element containing this attribute </summary>
43
/// <returns> Null if orphaned </returns>
44
public AXmlElement ParentElement {
46
AXmlTag tag = this.Parent as AXmlTag;
48
return tag.Parent as AXmlElement;
54
/// <summary> The part of name before ":"</summary>
55
/// <returns> Empty string if not found </returns>
56
public string Prefix {
58
return GetNamespacePrefix(this.Name);
62
/// <summary> The part of name after ":" </summary>
63
/// <returns> Whole name if ":" not found </returns>
64
public string LocalName {
66
return GetLocalName(this.Name);
71
/// Resolved namespace of the name. Empty string if not found
72
/// From the specification: "The namespace name for an unprefixed attribute name always has no value."
74
public string Namespace {
76
if (string.IsNullOrEmpty(this.Prefix)) return NoNamespace;
78
AXmlElement elem = this.ParentElement;
80
return elem.ResolvePrefix(this.Prefix);
82
return NoNamespace; // Orphaned attribute
86
/// <summary> Attribute is declaring namespace ("xmlns" or "xmlns:*") </summary>
87
public bool IsNamespaceDeclaration {
89
return this.Name == "xmlns" || this.Prefix == "xmlns";
96
public override void AcceptVisitor(IAXmlVisitor visitor)
98
visitor.VisitAttribute(this);
102
internal override bool UpdateDataFrom(AXmlObject source)
104
if (!base.UpdateDataFrom(source)) return false;
105
AXmlAttribute src = (AXmlAttribute)source;
106
if (this.Name != src.Name ||
107
this.EqualsSign != src.EqualsSign ||
108
this.QuotedValue != src.QuotedValue ||
109
this.Value != src.Value)
112
this.Name = src.Name;
113
this.EqualsSign = src.EqualsSign;
114
this.QuotedValue = src.QuotedValue;
115
this.Value = src.Value;
124
public override string ToString()
126
return string.Format(CultureInfo.InvariantCulture, "[{0} '{1}{2}{3}']", base.ToString(), this.Name, this.EqualsSign, this.Value);