Hoo to add an attribute to a node?

Hello together

I am building up a DOM from scratch, all works fine, except adding an
attribute to a node

Here is a small code snippet where I want to add the attribute to the node.
Whats wrong here??

....
      if(attributes)
      {
        myAttr = answerDocument.createAttribute(partialPath);
        myAttr.setValue("Attributes are stupid or not");
      }
      else
      {
        element = answerDocument.getElementsByTagName(partialPath);
      }

      try
      {
        nodeFound = element.item(0);
        String xyz = nodeFound.getNodeName();  //if node does not exist
throw exception
        nodeDoesExists = true;
        node = nodeFound;
      }
      catch(Exception e)
      {
        nodeDoesExists = false;

        if(attributes)
        {
          node.appendChild(myAttr); //add attribute to the node
        }

....

Thanks in advance
Mario

Received on Tuesday, 28 November 2000 02:11:02 UTC