String * XML::getTextContent(DOMNode * node)
{
String * res = new String(""); DOMNodeList * laListe = node->getChildNodes();
DOMNode * noeud_courant;
for(XMLSize_t i = 0; i < laListe->getLength(); i++)
{
noeud_courant = laListe->item(i);
// NodeType
switch(noeud_courant->getNodeType())
{
case DOMNode::ELEMENT_NODE:
{
printf("ELEMENT_NODE ");
String * tampon = getTextContent(noeud_courant);
*res += *tampon;
delete tampon;
break;
}
case DOMNode::ATTRIBUTE_NODE:
//pas de contenu texte ...
break;
case DOMNode::TEXT_NODE:
{char * tampon = XMLString::transcode(noeud_courant->getNodeValue());
printf("tampon = '%s'\n", tampon);
if(tampon != NULL)
*res += String(tampon);
delete [] tampon;
break;
}
case DOMNode::CDATA_SECTION_NODE:
case DOMNode::ENTITY_REFERENCE_NODE:
case DOMNode::ENTITY_NODE:
case DOMNode::PROCESSING_INSTRUCTION_NODE:
case DOMNode::COMMENT_NODE:
case DOMNode::DOCUMENT_NODE:
case DOMNode::DOCUMENT_TYPE_NODE:
case DOMNode::DOCUMENT_FRAGMENT_NODE:
case DOMNode::NOTATION_NODE:
default :
printf("Others: %d node\n", noeud_courant->getNodeType());
break;
}
}
return res;
}
where class String is a Al Dev's class.
This piece of code functions except with the accentuated letters (There is always nobody to help me with the accents?).
Gareth Reakes wrote:
Hi,
getTextContent does what you want but is unimplemented. If you decide to implement it then we will gladly accept your code :)
Gareth
On Thu, 27 Mar 2003, Magnus Strand wrote:
Hi,
Is there a method to return all text merged from all text subnodes from a certain nod in a DOM tree?
I mean if i have this as part of an xml: <header>It is <b>sunny</b>weather today</header>
I have a DOMNode* to the header element and would like to return all the text: "It is sunny weather today"
Regards,
Magnus Strand
-- Andre� V. FOMITCHEV [Quand faut-il arr�ter l'informatique] Software R&D Engineer [Lorsque, dans un kilo, on trouve 1024 grammes] Odixion, FRANCE
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
