Пример #1
0
        internal XmlAttribute(
            string prefix,
            string localName,
            string namespaceURI,
            XmlDocument doc,
            bool atomizedNames, bool checkNamespace) : base(doc)
        {
            if (!atomizedNames)
            {
                if (prefix == null)
                {
                    prefix = String.Empty;
                }
                if (namespaceURI == null)
                {
                    namespaceURI = String.Empty;
                }
            }

            // Prefix "xml" should be also checked (http://www.w3.org/XML/xml-names-19990114-errata#NE05)
            // but MS.NET ignores such case
            if (checkNamespace)
            {
                if (prefix == "xmlns" || (prefix == "" && localName == "xmlns"))
                {
                    if (namespaceURI != XmlNamespaceManager.XmlnsXmlns)
                    {
                        throw new ArgumentException("Invalid attribute namespace for namespace declaration.");
                    }
                    else if (prefix == "xml" && namespaceURI != XmlNamespaceManager.XmlnsXml)
                    {
                        throw new ArgumentException("Invalid attribute namespace for namespace declaration.");
                    }
                }
            }

            if (!atomizedNames)
            {
                // There are no means to identify the DOM is
                // namespace-aware or not, so we can only
                // check Name validity.
                if (prefix != "" && !XmlChar.IsName(prefix))
                {
                    throw new ArgumentException("Invalid attribute prefix.");
                }
                else if (!XmlChar.IsName(localName))
                {
                    throw new ArgumentException("Invalid attribute local name.");
                }

                prefix       = doc.NameTable.Add(prefix);
                localName    = doc.NameTable.Add(localName);
                namespaceURI = doc.NameTable.Add(namespaceURI);
            }
            name = doc.NameCache.Add(prefix, localName, namespaceURI, true);
        }
Пример #2
0
        public static string VerifyName(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentNullException("name");
            }

            if (!XmlChar.IsName(name))
            {
                throw new XmlException("'" + name + "' is not a valid XML Name");
            }
            return(name);
        }
Пример #3
0
 internal XmlAttribute(string prefix, string localName, string namespaceURI, XmlDocument doc, bool atomizedNames, bool checkNamespace) : base(doc)
 {
     if (!atomizedNames)
     {
         if (prefix == null)
         {
             prefix = string.Empty;
         }
         if (namespaceURI == null)
         {
             namespaceURI = string.Empty;
         }
     }
     if (checkNamespace && (prefix == "xmlns" || (prefix == string.Empty && localName == "xmlns")))
     {
         if (namespaceURI != "http://www.w3.org/2000/xmlns/")
         {
             throw new ArgumentException("Invalid attribute namespace for namespace declaration.");
         }
         if (prefix == "xml" && namespaceURI != "http://www.w3.org/XML/1998/namespace")
         {
             throw new ArgumentException("Invalid attribute namespace for namespace declaration.");
         }
     }
     if (!atomizedNames)
     {
         if (prefix != string.Empty && !XmlChar.IsName(prefix))
         {
             throw new ArgumentException("Invalid attribute prefix.");
         }
         if (!XmlChar.IsName(localName))
         {
             throw new ArgumentException("Invalid attribute local name.");
         }
         prefix       = doc.NameTable.Add(prefix);
         localName    = doc.NameTable.Add(localName);
         namespaceURI = doc.NameTable.Add(namespaceURI);
     }
     this.name = doc.NameCache.Add(prefix, localName, namespaceURI, true);
 }
Пример #4
0
 public static bool IsName(string s)
 {
     return(s != null && XmlChar.IsName(s));
 }