2 // Microsoft.Web.Services.Xml.QualifiedName.cs
4 // Author: Todd Berman <tberman@gentoo.org>
6 // (C) 2003 Todd Berman
11 namespace Microsoft
.Web
.Services
.Xml
13 public class QualifiedName
: XmlQualifiedName
16 private string _prefix
;
18 public QualifiedName (string prefix
, string name
, string namespaceURI
) : base (name
, namespaceURI
)
21 throw new ArgumentNullException ("prefix");
26 public static QualifiedName
FromString (string value, XmlNode node
)
29 throw new ArgumentNullException ("node");
32 if(value.IndexOf(':') > 0) {
33 string[] strings
= value.Split(':');
35 if(strings
.Length
!= 2 || strings
[0].Length
== 0 || strings
[1].Length
== 0) {
36 throw new FormatException ("xml_ImproperQName");
39 string nspace
= node
.GetNamespaceOfPrefix (strings
[0]);
42 throw new FormatException ("xml_CouldNotResolveNSPrefix");
45 if(nspace
.Length
== 0) {
46 throw new FormatException ("xml_CouldNotResolveNSPrefix");
49 return new QualifiedName (strings
[0], strings
[1], nspace
);
52 throw new FormatException ("xml_ImproperQName");
55 public XmlAttribute
GetNamespaceDecl (XmlDocument document
)
57 if(document
== null) {
58 throw new ArgumentNullException ("document");
60 XmlAttribute attrib
= document
.CreateAttribute("xmlns",
62 "http://www.w3.org/2000/xmlns");
64 attrib
.Value
= Namespace
;
68 public void GetQualifiedName (XmlDocument document
, XmlElement element
)
70 if(document
== null) {
71 throw new ArgumentNullException ("document");
74 throw new ArgumentNullException ("element");
76 element
.InnerText
= Value
;
77 if(Namespace
!= element
.NamespaceURI
) {
78 element
.Attributes
.Append(GetNamespaceDecl(document
));
82 public string Prefix
{
83 get { return _prefix; }
87 get { return _prefix + ":" + Name; }