Example #1
0
        public static bool IsNCName(string str)
        {
            if (str == null)
            {
                return(false);
            }
            else
            {
                int len = str.Length;
                switch (len)
                {
                case 0:
                    return(false);

                case 1:
                    return(NCName.IsNCNameStart(str[0]));

                default:
                    if (!NCName.IsNCNameStart(str[0]))
                    {
                        return(false);
                    }
                    for (int i = 1; i < len; i++)
                    {
                        if (!NCName.IsNCNameTrail(str[i]))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
            }
        }
Example #2
0
        // [NOCPP[

        internal void ProcessNonNcNames <T>(TreeBuilder <T> treeBuilder, XmlViolationPolicy namePolicy) where T : class
        {
            for (int i = 0; i < length; i++)
            {
                AttributeName attName = names[i];
                if (!attName.IsNcName(mode))
                {
                    string name = attName.GetLocal(mode);
                    switch (namePolicy)
                    {
                    case XmlViolationPolicy.AlterInfoset:
                        names[i] = AttributeName.Create(NCName.EscapeName(name));
                        goto case XmlViolationPolicy.Allow;                                 // fall through

                    case XmlViolationPolicy.Allow:
                        if (attName != AttributeName.XML_LANG)
                        {
                            treeBuilder.Warn("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0.");
                        }
                        break;

                    case XmlViolationPolicy.Fatal:
                        treeBuilder.Fatal("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0.");
                        break;
                    }
                }
            }
        }