예제 #1
0
      public void Length_should_equal_original_length() {
        var attributes = new Attributes();
        attributes.AddAttribute(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
        attributes.AddAttribute(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);

        var copy = new Attributes(attributes);

        Assert.Equal(copy.Length, attributes.Length);
      }
예제 #2
0
    ////
    /// <summary>
    ///     Sets an attribute and its value into an Attributes object.
    ///     Attempts to set a namespace declaration are ignored.
    /// </summary>
    /// <param name="atts">
    ///     The AttributesImpl object
    /// </param>
    /// <param name="name">
    ///     The name (Qname) of the attribute
    /// </param>
    /// <param name="type">
    ///     The type of the attribute
    /// </param>
    /// <param name="value">
    ///     The value of the attribute
    /// </param>
    public void SetAttribute(Attributes atts, string name, string type, string value) {
      if (name.Equals("xmlns") || name.StartsWith("xmlns:")) {
        return;
      }

      string ns = GetNamespace(name, true);
      string localName = GetLocalName(name);
      int i = atts.GetIndex(name);
      if (i == -1) {
        name = string.Intern(name);
        if (type == null) {
          type = "CDATA";
        }
        if (!type.Equals("CDATA")) {
          value = Normalize(value);
        }
        atts.AddAttribute(ns, localName, name, type, value);
      } else {
        if (type == null) {
          type = atts.GetType(i);
        }
        if (!type.Equals("CDATA")) {
          value = Normalize(value);
        }
        atts.SetAttribute(i, ns, localName, name, type, value);
      }
    }