ooops, when i find an element node and want to set a new value for it, i
have to
seek for the appropriate child node with name "#text" and set the value for
this
child node. please try to call this function when you have found a node by
name:

/**
     * Sets a tag's value by given node.
     *
     * @param     n             the node of the tag
     * @param     value_new     the new value for the tag
     * @return    value_old     the old value of the tag in a string
     *
     */

    private String SetValueByNode(Node n, String value_new)
    {
      String value_old = "";
      
      if (null != n)
         {
           NodeList nl = n.getChildNodes();
         Node cn = null;
         int type = -1;
         int len = nl.getLength();
         for ( int i = 0; i < len; i++ )
             {
             cn = nl.item(i);
             type = cn.getNodeType();
             if ( type == Node.TEXT_NODE )
                {
                value_old = cn.getNodeValue();
                cn.setNodeValue(value_new);
                break;
                }
             }
         }

      return value_old;
    }

cheers,

Peter


> -----Urspr�ngliche Nachricht-----
> Von: Esteban Gonzalez [mailto:[EMAIL PROTECTED]
> Gesendet: Dienstag, 12. M�rz 2002 18:27
> An: [EMAIL PROTECTED]
> Betreff: Re: Xerces templating
> 
> 
> Peter,
>     Here are some snippets of the code...
>                 try
>                 {
>                         //DOMParser parser = new DOMParser();
>                         DocumentBuilder parser =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>                         template = parser.parse( uri );
>                         //parseAndPrint( template );
>                 }
>                 catch( Exception e )
>                 {
>                         System.err.println("Sorry, error 
> ocurred " + e );
>                 }
> 
>                 .....
>                 Node vouchersElement =
> doc.importNode(template.getDocumentElement(),true);
>                 ........
>                 Node voucherElement = vouchersElement.getFirstChild();
>                 NodeList list = voucherElement.getChildNodes();
>                             for(int k=0; k<list.getLength(); k++)
>                                 {
>                                         Node item = list.item(k);
> 
>                                         if(
> item.getNodeName().equals("cliente") )
>                                         {
>                                                 NodeList cliatt =
> item.getChildNodes();
>                                                 for(int j=0;
> j<list.getLength(); j++)
>                                                 {
>                                                         Node attr =
> list.item(j);
>                                                         if(
> attr.getNodeName().equals("pais") )
> 
> item.setNodeValue( "1000" );
>                                                         if(
> attr.getNodeName().equals("codigo") )
> 
> item.setNodeValue( "jua jua jua");
>                                                 }
>                                         }
>                                 }
>                                 vouchersElement.appendChild( vou );
>                         }
>                         doc.appendChild( vouchersElement );
> 
> That should be it..
> it�s not the real source, but rather one that i used to play 
> around and test
> if it worked out the templating idea... seems like i�m doing 
> something wrong
> ... =(
> 
> I would appreciate any help...
> 
> best regards,
> Esteban
> 
> ----- Original Message -----
> From: "Hellmann Peter (ext) ICM RDC IS VDR RD"
> <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, March 12, 2002 1:06 PM
> Subject: AW: Xerces templating
> 
> 
> Esteban,
> 
> no, it is not a correct behaviour for the dom api since the 
> creation of a
> dom tree is
> good for manipulting the document programmatically. If you 
> add, delete or
> change nodes
> and afterwards serialize the document, the serialized document should
> reflect any changes.
> 
> What functions do you call for altering the document? Can you 
> provide some
> source?
> 
> cheers
> 
> Peter
> 
> > -----Urspr�ngliche Nachricht-----
> > Von: Esteban Gonzalez [mailto:[EMAIL PROTECTED]
> > Gesendet: Dienstag, 12. M�rz 2002 15:49
> > An: [EMAIL PROTECTED]
> > Betreff: Xerces templating
> >
> >
> > HI!
> > I�m not really sure if this is the place to post this
> > question... but i�m
> > having a little problem here and I need some help ....
> >
> > I have a voucher.xml file wich is a �template� to create new
> > xml voucher
> > representations.
> >
> > I�m using Xerces, latest version, downloaded a week ago.
> > When i do
> > doc = parser.parse ( uri )
> >
> > I get the document with the DOM representation of the xml
> > file ( wich it�s
> > fine, since printing it shows an exact copy of my 
> voucher.xml file ).
> > So far there are no problems..
> > The problem comes when i try to change the data that is on
> > the document...
> > adding nodes will result in nothing...
> > deleting them ends up on nothing but the �doc� object being 
> always the
> > same..
> >
> > It this a correct behaviour for the dom api?
> > Am i doing something wrong?
> > Should i import the root element into a new document and
> > change that one?
> >
> > Am i missing something? reading at the API hasn�t been very
> > helpful....
> >
> >
> > --------------------------------------------
> > Esteban Gonzalez
> > Departamento de Sistemas
> >
> > ASSIST-CARD International
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to