DOM, how to get text out of text node

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

DOM, how to get text out of text node

Andrea-29
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() );
            }
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml
Reply | Threaded
Open this post in threaded view
|

Re: DOM, how to get text out of text node

Doron Rosenberg-2
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.
_______________________________________________
dev-tech-xml mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xml