if DOM doesn't allow you to modify the tree, then why are there
"setAttribute" methods? and create...() methods??
one of the really really nice things (IMNSHO) about XPATH, is the ability to
select out a particular node and modify it without having to walk
through the entire tree!
this code works for me:
Document doc = . . .;
String PICTURE = "picture";
String NAME = "name";
String FILENAME = "foo.jpg";
.
.
.
// Create a <picture name="foo.jpg"> element & attribute
Element picture = doc.createElement( PICTURE );
Attr picname = doc.createAttribute( NAME );
picture.setAttributeNode( picname );
picture.setAttribute(NAME, FILENAME);
/** then go on to add child text nodes and append it to
* the appropriate node in the document.
* If you like, i can give you that code too...
*/
On Fri, 9 Nov 2001 12:15:34 +0100, Saigal, Ankur wrote:
>From My knowledge,,,DOM doesnot allow u to modify the tree,,,the only think
>u can do is to create a new DOM and copy the required attributes (etcetra)
>with changed values..
>
>Regards,
>Ankur
>
>-----Original Message-----
>From: longinus [mailto:[EMAIL PROTECTED]
>Sent: Friday, November 09, 2001 4:42 PM
>To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
>Subject: changing attribute value of the node
>
>
>I want to change the value of the first child in the document.
>I do it this way but it doesn't work.
>
>Node n=doc.getFirstChild();
>Element el=(Element)n;
>el.setAttribute("data","dsgsdgdf");
>theFormDOM.getDOM().replaceChild((Node)el,n);
>
>Note that that first child may already have the data attribute. It
>doesn't work, exception is generated.
>
>Second try:
>
>Node n=doc.getFirstChild();
>Attr data=(theFormDOM.getDOM()).createAttribute("data");
>data.setValue("no co jest?");
>if(n.hasAttributes())
> ((Element)n).removeAttribute("data");
>
>((Element)n).setAttributeNode(data);
>
>The same result.
>
>How can I modify the value of the attribute ?
>
--------------------------------------------
<argo_tec gmbh>
ed.q.bridges
tel. 089-368179.552
fax 089-368179.79
osterwaldstra�e 10
(haus F eingang 21)
80805 m�nchen
</argo_tec gmbh>
--------------------------------------------