System.Xml.ValidateNames.ParseQName C# (CSharp) Méthode

ParseQName() static private méthode

Attempts to parse the input string as a QName (see the XML Namespace spec). Quits parsing when an invalid QName char is reached or the end of string is reached. Returns the number of valid QName chars that were parsed. Sets colonOffset to the offset of a colon character if it exists, or 0 otherwise.
static private ParseQName ( string s, int offset, int &colonOffset ) : int
s string
offset int
colonOffset int
Résultat int
        internal static int ParseQName(string s, int offset, out int colonOffset)
        {
            int len, lenLocal;

            // Assume no colon
            colonOffset = 0;

            // Parse NCName (may be prefix, may be local name)
            len = ParseNCName(s, offset);
            if (len != 0)
            {
                // Non-empty NCName, so look for colon if there are any characters left
                offset += len;
                if (offset < s.Length && s[offset] == ':')
                {
                    // First NCName was prefix, so look for local name part
                    lenLocal = ParseNCName(s, offset + 1);
                    if (lenLocal != 0)
                    {
                        // Local name part found, so increase total QName length (add 1 for colon)
                        colonOffset = offset;
                        len += lenLocal + 1;
                    }
                }
            }

            return len;
        }

Usage Example

        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)));
            }
        }
All Usage Examples Of System.Xml.ValidateNames::ParseQName