You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Luke Blanshard <lu...@quiq.com> on 2000/10/10 00:38:21 UTC

Re: Extracting a value from a DOM element node

nunez@helios.net wrote:

> From the API it seems that you would use getNodeValue, however this
> returns null.

Yeah, it isn't obvious.  However, element nodes' values are always null.

The nodes of a DOM tree include lots of kinds of things, more than just elements.  For example, all the
text between successive elements is put together into a node.  This is why:

> If I take the length of settings at this point, I get 11, so I know
> that something isn't quite right.

You have 5 child elements and 6 child text nodes.  The text nodes contain the white space between the
child elements.

This is also how you get hold of the text within the child elements, for example the absence_weight
element.  You get ITS child nodes; it should have exactly one, and it should be a text node.  You ask
THAT node for its node value, and you'll get the string you were expecting.

If you get to decide what your DTD looks like, you might consider putting these settings in as
attributes of the settings element, instead of child elements:

<!ELEMENT settings EMPTY>
<!ATTLIST settings
    absence_weight    CDATA    #REQUIRED
    match_weight    CDATA    #REQUIRED
    mismatch_weight    CDATA    #REQUIRED
    description_weight    CDATA    #REQUIRED
    max_matches    CDATA    #REQUIRED
>

Luke

> <?xml version="1.0" encoding="us-ascii" standalone="yes"?>
> <!-- $Id$  -->
> <!-- An example casebase -->
>
> <!DOCTYPE casebase [
> <!ELEMENT casebase (settings)>
> <!ELEMENT settings (absence_weight, match_weight, mismatch_weight, description_weight, max_matches)>
> <!ELEMENT absence_weight (#PCDATA)>
> <!ELEMENT match_weight (#PCDATA)>
> <!ELEMENT mismatch_weight (#PCDATA)>
> <!ELEMENT description_weight (#PCDATA)>
> <!ELEMENT max_matches (#PCDATA)>
> ]>
>
> <casebase id="printer">
>     <settings>
>         <absence_weight>0</absence_weight>
>         <match_weight>10</match_weight>
>         <mismatch_weight>-2</mismatch_weight>
>         <description_weight>20</description_weight>
>         <max_matches>10</max_matches>
>     </settings>
> </casebase>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org