W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

Hoo to add an attribute to a node?

From: <mario.heiss@gerling.de>
Date: Tue, 28 Nov 2000 08:10:22 +0100
Message-ID: <6B682B561242D3119B5800805F8B6C3E04020775@tmdecgn0003.decgn.gerling.com>
To: www-dom@w3.org
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT