You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Tommy Santoso <To...@dresdner-bank.com> on 2000/10/10 20:06:52 UTC

NodeList: getNodeValue()

Developer team,

I need to create an extension java function, that works with a nodelist.

According to the xalan-java extension doc, it should be possible to pass
the nodelist:
for eg (from: http://xml.apache.org/xalan/extensions.html)
-------------
                 public static boolean doSomething(org.w3c.dom.NodeList
nList)

                 Assuming you set up this extension in the node-ext
namespace, any of the following
                 extension calls from a stylesheet are syntactically
possible:
-----------
                  <!--Process all nodes in current context-->
                 <xsl:variable name="success"
                 select="myExtension:myMethod(*)"/>

How can I retrieve the value of the nodes ? I tried with the method
getNodeValue(), but this function always returns null:

Here is my source code:

public String myMethod(
          NodeList nlist
     )
     {
     try{
        for (int i=0; i< nlist.getLength(); i++){
               Node nd = nlist.item(i);
               // printed to logfile, getNodeValue() returned null
               printToLog("Node value: "+nd.getNodeValue());
                //printed to logfile, getNodeType() returned 1
               printToLog("Node type: "+nd.getNodeType());
          }
          }catch(FileNotFoundException e){}
          return "";
     }

Where did I do wrong?

Thanks in advance,

Tommy Santoso


Re: NodeList: getNodeValue()

Posted by Gary L Peskin <ga...@firstech.com>.
Tommy Santoso wrote:
> 
> Developer team,
> 
> I need to create an extension java function, that works with a nodelist.
> 
> According to the xalan-java extension doc, it should be possible to pass
> the nodelist:
> for eg (from: http://xml.apache.org/xalan/extensions.html)
> -------------
>                  public static boolean doSomething(org.w3c.dom.NodeList
> nList)

Yes.

> How can I retrieve the value of the nodes ? I tried with the method
> getNodeValue(), but this function always returns null:

Tommy, have a look at the table at
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1841493061

In your

 select="myExtension:myMethod(*)

* is short for child::*.  These will retrieve all element nodes which
are children of the current node.

The value returned by getNodeValue() depends on the node type.  For
element nodes, the nodeValue is null.  You should use getNodeName() for
those to get the tag name.

Please let us know if this helps.

Gary