How to use appendChild()?(com.docuverse.dom.BasicAttribute)

Hello:
I want to know why there is a HTTP 500 error if there is the last two rows code:
//------------------------------------
BasicDocument doc = new BasicDocument();
BasicElement rootElement = new BasicElement(doc, “rootElement”);

BasicElement node1 = new BasicElement(doc,“node1”);
rootElement.appendChild(node1);

BasicAttribute node1attr = new BasicElement(doc,“node1attr”,“attrvalue”);
node1.appendChild(node1attr);
//---------------------------------

[This message was edited by wangsir on 11 Mar 2002 at 09:12.]

Hi,

could it be that the modifications in the last two lines of code create a document which no longer complies to the schema?

There will probably be more information in the error log of the Servlet/Container Engine.

If you could supply some more information on your application (Tamino version, Servlet Engine, etc) we could be of more help!

Thanks,
Trevor.

Hi:
Thanks!
My development environment:
Tamino2.3.1.4+Apache1.3.22+Tomcat3.20.
My intent is adding a data via Jsp,for example:




I am looking forward to.

Hello.

The last two lines look a little strange:
BasicAttribute node1attr = new BasicElement(doc,“node1attr”,“attrvalue”);

Is this correct? Should the instantiation be of a “new BasicAttribute” too?

(This looks likely to cause a problem at some point - instantiating a BasicElement into a BasicAttribute field…)

Also, I am not sure, but I think that appendChild() may be the wrong way to set an attribute. Isn’t Element.setAttribute(String name, String value) better - or even Element.setAttributeNode(org.w3c.dom.Attr)?

Perhaps someone more familiar with DOM can comment on this…

Cheers,
Trevor.

If you are appending a node as an attribute it should be an instance of an attribute not an element. When the parser checks the nodetype it will get a ELEMENT_NODE type, therefore it will just append an element to your parent node instead of an attribute. Usually, the Element object has a setAttribute method you can use. If you really need to do it by appending, create the instance using the constructor of an attribute node, not an element.

Sorry,sorry for my carelessness,and Trevor is right.I should have written to “new BasicAttribute”,sorry!
According to what Jfarjona said,I solved it,thanks!