示例#1
0
 protected void writeAttribute(Attributes attributes, int index) throws IOException {
   char quote = format.getAttributeQuoteCharacter();
   writer.write(" ");
   writer.write(attributes.getQName(index));
   writer.write("=");
   writer.write(quote);
   writeEscapeAttributeEntities(attributes.getValue(index));
   writer.write(quote);
 }
示例#2
0
  protected void writeAttribute(Attribute attribute) throws IOException {
    writer.write(" ");
    writer.write(attribute.getQualifiedName());
    writer.write("=");

    char quote = format.getAttributeQuoteCharacter();
    writer.write(quote);

    writeEscapeAttributeEntities(attribute.getValue());

    writer.write(quote);
    lastOutputNodeType = Node.ATTRIBUTE_NODE;
  }
示例#3
0
  /**
   * Writes the attributes of the given element
   *
   * @param element DOCUMENT ME!
   * @throws IOException DOCUMENT ME!
   */
  protected void writeAttributes(Element element) throws IOException {
    // I do not yet handle the case where the same prefix maps to
    // two different URIs. For attributes on the same element
    // this is illegal; but as yet we don't throw an exception
    // if someone tries to do this
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
      Attribute attribute = element.attribute(i);
      Namespace ns = attribute.getNamespace();

      if ((ns != null) && (ns != Namespace.NO_NAMESPACE) && (ns != Namespace.XML_NAMESPACE)) {
        String prefix = ns.getPrefix();
        String uri = namespaceStack.getURI(prefix);

        if (!ns.getURI().equals(uri)) {
          writeNamespace(ns);
          namespaceStack.push(ns);
        }
      }

      // If the attribute is a namespace declaration, check if we have
      // already written that declaration elsewhere (if that's the case,
      // it must be in the namespace stack
      String attName = attribute.getName();

      if (attName.startsWith("xmlns:")) {
        String prefix = attName.substring(6);

        if (namespaceStack.getNamespaceForPrefix(prefix) == null) {
          String uri = attribute.getValue();
          namespaceStack.push(prefix, uri);
          writeNamespace(prefix, uri);
        }
      } else if (attName.equals("xmlns")) {
        if (namespaceStack.getDefaultNamespace() == null) {
          String uri = attribute.getValue();
          namespaceStack.push(null, uri);
          writeNamespace(null, uri);
        }
      } else {
        char quote = format.getAttributeQuoteCharacter();
        writer.write(" ");
        writer.write(attribute.getQualifiedName());
        writer.write("=");
        writer.write(quote);
        writeEscapeAttributeEntities(attribute.getValue());
        writer.write(quote);
      }
    }
  }