Esempio n. 1
0
        // ]NOCPP]

        internal void AddAttribute(AttributeName name, string value
                                   // [NOCPP[
                                   , XmlViolationPolicy xmlnsPolicy
                                   // ]NOCPP]
                                   )
        {
            // [NOCPP[
            if (name == AttributeName.ID)
            {
                idValue = value;
            }

            if (name.IsXmlns)
            {
                if (xmlnsNames.Length == xmlnsLength)
                {
                    int             newLen   = xmlnsLength == 0 ? 2 : xmlnsLength << 1;
                    AttributeName[] newNames = new AttributeName[newLen];
                    Array.Copy(xmlnsNames, newNames, xmlnsNames.Length);

                    xmlnsNames = newNames;
                    string[] newValues = new string[newLen];
                    Array.Copy(xmlnsValues, newValues, xmlnsValues.Length);
                    xmlnsValues = newValues;
                }
                xmlnsNames[xmlnsLength]  = name;
                xmlnsValues[xmlnsLength] = value;
                xmlnsLength++;
                switch (xmlnsPolicy)
                {
                case XmlViolationPolicy.Fatal:
                    // this is ugly (TODO)
                    throw new Exception("Saw an xmlns attribute.");

                case XmlViolationPolicy.AlterInfoset:
                    return;

                case XmlViolationPolicy.Allow:
                    break;                             // fall through
                }
            }

            // ]NOCPP]

            if (names.Length == length)
            {
                int newLen = length << 1;                 // The first growth covers virtually
                // 100% of elements according to
                // Hixie
                AttributeName[] newNames = new AttributeName[newLen];
                Array.Copy(names, newNames, names.Length);
                names = newNames;
                string[] newValues = new string[newLen];
                Array.Copy(values, newValues, values.Length);
                values = newValues;
            }
            names[length]  = name;
            values[length] = value;
            length++;
        }
Esempio n. 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;
                    }
                }
            }
        }
 /**
  * Sets the contentNonXmlCharPolicy.
  *
  * @param contentNonXmlCharPolicy
  *            the contentNonXmlCharPolicy to set
  */
 public override void setContentNonXmlCharPolicy(
         XmlViolationPolicy contentNonXmlCharPolicy)
 {
     this.contentNonXmlCharPolicy = contentNonXmlCharPolicy;
 }