Re: DOM, how to get text out of text node
Doron Rosenberg <[email protected]> Fri, 19 May 2006 13:38:52 -0500
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
Andrea Belvedere wrote:
> Hi all,
> i am stack on this:
> i am parsing a dom document, i reach a text node, but i can't get the
> text out of the text node.
> Hope some one can help.
> this is the code:
>
> childs is a nsIDOMNodeList.
>
> PRUint32 len, i;
> childs->GetLength( &len );
> nsCOMPtr<nsIDOMNode> child;
> nsEmbedString name;
> nsEmbedString value;
> PRUint16 type;
> for( i = 0; i < len; i++ ) {
> childs->Item( i, getter_AddRefs( child ) );
> child->GetNodeType( &type );
> child->GetLocalName( name );
>
> // TEXT_NOTE here
> if( type == nsIDOMNode::TEXT_NODE ) {
> httpsec_log( stderr, "%s\n", "TEXT_NODE" );
> nsCOMPtr<nsIDOMText> data = do_QueryInterface( child );
> NS_ENSURE_TRUE( data, NS_ERROR_UNEXPECTED );
>
> data->GetData( value );
> // there is nothing in value, when i print it
> httpsec_log( stderr, "%s\n", NS_ConvertUTF16toUTF8(
> value ).get() );
> data->GetNodeValue( value );
> // again nothing here
> httpsec_log( stderr, "%s\n", NS_ConvertUTF16toUTF8(
> value ).get() );
> }
You want DOMNode->GetNodeValue() - see nsIDOMNode.idl.