Contains various static functions and methods for parsing and validating: NCName (not namespace-aware, no colons allowed) QName (prefix:local-name)
Example #1
0
        private static void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(SR.Xml_EmptyName);
            }
            int len = ValidateNames.ParseNCName(ncname, 0);

            if (len != ncname.Length)
            {
                throw new ArgumentException(SR.Format(len == 0 ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(ncname, len)));
            }
        }
        private void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.Xml_EmptyName));
            }
            int len = ValidateNames.ParseNCName(ncname, 0);

            if (len != ncname.Length)
            {
                throw new ArgumentException(Res.GetString(len == 0 ? Res.Xml_BadStartNameChar : Res.Xml_BadNameChar, XmlException.BuildCharExceptionStr(ncname[len])));
            }
        }
 private void ValidateQName(string prefix, string localName)
 {
     try {
         if (prefix.Length > 0)
         {
             ValidateNames.ParseNCNameThrow(prefix);
         }
         ValidateNames.ParseNCNameThrow(localName);
     }
     catch {
         state = State.Error;
         throw;
     }
 }
        private void ValidateQName(string name)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException(SR.Xml_EmptyName);
            }
            int colonPos;
            int len = ValidateNames.ParseQName(name, 0, out colonPos);

            if (len != name.Length)
            {
                string res = (len == 0 || (colonPos > -1 && len == colonPos + 1)) ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar;
                throw new ArgumentException(string.Format(res, XmlException.BuildCharExceptionArgs(name, len)));
            }
        }
        private void ValidateQName(string name)
        {
            if (name.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.Xml_EmptyName));
            }
            int colonPos;
            int len = ValidateNames.ParseQName(name, 0, out colonPos);

            if (len != name.Length)
            {
                string res = (len == 0 || (colonPos > -1 && len == colonPos + 1)) ? Res.Xml_BadStartNameChar : Res.Xml_BadNameChar;
                throw new ArgumentException(Res.GetString(res, XmlException.BuildCharExceptionStr(name[len])));
            }
        }
        private void ValidateQName(string name)
        {
            int num;

            if (name.Length == 0)
            {
                throw new ArgumentException(Res.GetString("Xml_EmptyName"));
            }
            int invCharIndex = ValidateNames.ParseQName(name, 0, out num);

            if (invCharIndex != name.Length)
            {
                string str = ((invCharIndex == 0) || ((num > -1) && (invCharIndex == (num + 1)))) ? "Xml_BadStartNameChar" : "Xml_BadNameChar";
                throw new ArgumentException(Res.GetString(str, XmlException.BuildCharExceptionArgs(name, invCharIndex)));
            }
        }
Example #7
0
        public static string VerifyQName(string name, ExceptionType exceptionType)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            int colonPosition = -1;

            int endPos = ValidateNames.ParseQName(name, 0, out colonPosition);

            if (endPos != name.Length)
            {
                throw CreateException(SR.Xml_BadNameChar, XmlExceptionHelper.BuildCharExceptionArgs(name, endPos), exceptionType, 0, endPos + 1);
            }
            return(name);
        }
Example #8
0
        internal static string VerifyQName(string name, ExceptionType exceptionType)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentNullException(nameof(name));
            }

            int colonPosition = -1;

            int endPos = ValidateNames.ParseQName(name, 0, out colonPosition);

            if (endPos != name.Length)
            {
                throw CreateException(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, endPos), exceptionType, 0, endPos + 1);
            }
            return(name);
        }
        internal static XmlQualifiedName Parse(string s, IXmlNamespaceResolver nsmgr, out string prefix)
        {
            string str;

            ValidateNames.ParseQNameThrow(s, out prefix, out str);
            string ns = nsmgr.LookupNamespace(prefix);

            if (ns == null)
            {
                if (prefix.Length != 0)
                {
                    throw new XmlException("Xml_UnknownNs", prefix);
                }
                ns = string.Empty;
            }
            return(new XmlQualifiedName(str, ns));
        }
Example #10
0
        internal static string VerifyNMTOKEN(string name, ExceptionType exceptionType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw CreateException(SR.Xml_InvalidNmToken, name, exceptionType);
            }

            int endPos = ValidateNames.ParseNmtokenNoNamespaces(name, 0);

            if (endPos != name.Length)
            {
                throw CreateException(SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, endPos), exceptionType, 0, endPos + 1);
            }
            return(name);
        }
Example #11
0
        internal static XmlQualifiedName Parse(string s, IXmlNamespaceResolver nsmgr, out string prefix)
        {
            string localName;

            ValidateNames.ParseQNameThrow(s, out prefix, out localName);

            string uri = nsmgr.LookupNamespace(prefix);

            if (uri == null)
            {
                if (prefix.Length != 0)
                {
                    throw new XmlException(Res.Xml_UnknownNs, prefix);
                }
                else   //Re-map namespace of empty prefix to string.Empty when there is no default namespace declared
                {
                    uri = string.Empty;
                }
            }
            return(new XmlQualifiedName(localName, uri));
        }
Example #12
0
        internal static string VerifyNCName(string name, ExceptionType exceptionType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentNullException("name", SR.Xml_EmptyLocalName);
            }

            int end = ValidateNames.ParseNCName(name, 0);

            if (end != name.Length)
            {
                // If the string is not a valid NCName, then throw or return false
                throw CreateInvalidNameCharException(name, end, exceptionType);
            }

            return(name);
        }
Example #13
0
        //
        // Verification methods for strings
        //
        /// <include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.VerifyName"]/*' />
        /// <devdoc>
        ///    <para>
        ///    </para>
        /// </devdoc>
        public static string VerifyName(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentNullException("name", SR.Xml_EmptyName);
            }

            // parse name
            int endPos = ValidateNames.ParseNameNoNamespaces(name, 0);

            if (endPos != name.Length)
            {
                // did not parse to the end -> there is invalid character at endPos
                throw CreateInvalidNameCharException(name, endPos, ExceptionType.XmlException);
            }
            return(name);
        }
Example #14
0
        private void ValidateQName(string name)
        {
            string prefix, localName;

            ValidateNames.ParseQNameThrow(name, out prefix, out localName);
        }
 private static void ValidateQName(string name)
 {
     ValidateNames.ParseQNameThrow(name);
 }