/* (non-Javadoc)
   * @see org.eclipse.ohf.utilities.xml.IXMLWriter#open(java.lang.String, java.lang.String, java.lang.String)
   */
  @Override
  public void open(String namespace, String name, String comment) throws IOException {
    if (!XMLUtil.isNMToken(name)) throw new IOException("XML name " + name + " is not valid");
    checkStarted();
    if (pendingClose) {
      write('>');
      writePendingComment();
      pendingClose = false;
    }

    if (name == null) {
      throw new IOException("name is null");
    }
    newLevelIfRequired();
    levels.current().setName(name);
    levels.current().setNamespace(namespace);
    int col = writePretty();
    write('<');
    if (namespace == null) {
      write(name);
      col = col + name.length() + 1;
    } else {
      String n = getNSAbbreviation(namespace) + name;
      write(n);
      col = col + n.length() + 1;
    }
    writeAttributes(col);
    pendingOpen = false;
    pendingClose = true;
    pendingComment = comment;
  }
 /* (non-Javadoc)
  * @see org.eclipse.ohf.utilities.xml.IXMLWriter#element(java.lang.String, java.lang.String, java.lang.String)
  */
 @Override
 public void element(String namespace, String name, String content) throws IOException {
   if (!XMLUtil.isNMToken(name)) throw new IOException("XML name " + name + " is not valid");
   open(namespace, name);
   text(content);
   close();
 }
  private void addAttribute(String name, String value, boolean noLines) throws IOException {
    if (!XMLUtil.isNMToken(name))
      throw new IOException("XML name " + name + " is not valid for value '" + value + "'");

    newLevelIfRequired();
    value = XMLUtil.escapeXML(value, charset, noLines);

    if (attributes == null) attributes = new String[][] {{name, value}};
    else {
      String[][] newattr = new String[attributes.length + 1][];
      for (int i = 0; i < attributes.length; i++) {
        condition(
            !attributes[i][0].equals(name),
            "attempt to define attribute with name "
                + name
                + " more than once for value '"
                + value
                + "'");
        newattr[i] = attributes[i];
      }
      attributes = newattr;
      attributes[attributes.length - 1] = new String[] {name, value};
    }
  }