const char *xml = "<test><tag>content 1</tag><tag>co<a href=\"#test\" target=\"xx\">ntent</a> 2</tag> "
"<othertag>wrongcontent</othertag>"
"<tag>content 3</tag></test>";
int main(){
DomElementContainer c(doc, "a");
int link = 0;
link++;
}
qDebug() << "### total link found -> " << link;
return 0;
}
const char *xml = "<test><tag>content 1</tag><tag>co<a href=\"#test\" target=\"xx\">ntent</a> 2</tag> "
"<othertag>wrongcontent</othertag>"
"<tag>content 3</tag></test>";
int main(){
QDomDocument doc;
doc.setContent(QString(xml));
DomElementContainer c(doc, "a");
int link = 0;
foreach(QDomElement e, c) {
link++;
}
qDebug() << "### total link found -> " << link;
return 0;
}
To copy to clipboard, switch view to plain text mode
function Rewrite_QT_Tag($xhtml) {
/* rewrite not support target on QTextedit tag <a> */
/* samble : <a href="http://www.qtcentre.org/#target=_blank">
<span style=" text-decoration: underline; color:#0000ff;">QtCentre</span>
</a>*/
$dom = new XML();
$dom->loadXML($xhtml);
$xp = new DomXPath($dom);
$xp ->registerNamespace('default','http://www.w3.org/1999/xhtml');
$result = $xp->query("//default:a");
foreach ($result as $node) {
$attuale = $node->getAttribute("href");
/* get text from qt span and insert text node.... */
$testodentro ="";
while($node->hasChildNodes()) {
/* get span text inside <a><span>text link</span></a>*/
$testodentro .=$node->childNodes->item(0)->nodeValue;
$node->removeChild($node->childNodes->item(0));
}
$testodentro = eregi_replace("\n"," ",$testodentro);
$testo = $dom->createTextNode($testodentro);
$node->appendChild($testo);
/* rewrite target */
if (eregi("#target=",$attuale)) {
$params = explode("#target=", $attuale);
$urigo = $params[0];
$node->setAttribute("href",$urigo);
/**/
if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $urigo )) {
$node->setAttribute("target","_blank");
$node->setAttribute("class","Link_External");
} else if (eregi('mailto:',$urigo)) {
$node->setAttribute("class","Link_Mail");
} else {
$node->setAttribute("target",$params[1]);
$node->setAttribute("class","Link_Internal");
}
/**/
} else if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $attuale )) {
$node->setAttribute("target","_blank");
$node->setAttribute("class","Link_External");
} else {
continue;
}
}
/* end link rewrite */
$xhtml = $dom->saveXML();
return $xhtml;
}
function Rewrite_QT_Tag($xhtml) {
/* rewrite not support target on QTextedit tag <a> */
/* samble : <a href="http://www.qtcentre.org/#target=_blank">
<span style=" text-decoration: underline; color:#0000ff;">QtCentre</span>
</a>*/
$dom = new XML();
$dom->loadXML($xhtml);
$xp = new DomXPath($dom);
$xp ->registerNamespace('default','http://www.w3.org/1999/xhtml');
$result = $xp->query("//default:a");
foreach ($result as $node) {
$attuale = $node->getAttribute("href");
/* get text from qt span and insert text node.... */
$testodentro ="";
while($node->hasChildNodes()) {
/* get span text inside <a><span>text link</span></a>*/
$testodentro .=$node->childNodes->item(0)->nodeValue;
$node->removeChild($node->childNodes->item(0));
}
$testodentro = eregi_replace("\n"," ",$testodentro);
$testo = $dom->createTextNode($testodentro);
$node->appendChild($testo);
/* rewrite target */
if (eregi("#target=",$attuale)) {
$params = explode("#target=", $attuale);
$urigo = $params[0];
$node->setAttribute("href",$urigo);
/**/
if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $urigo )) {
$node->setAttribute("target","_blank");
$node->setAttribute("class","Link_External");
} else if (eregi('mailto:',$urigo)) {
$node->setAttribute("class","Link_Mail");
} else {
$node->setAttribute("target",$params[1]);
$node->setAttribute("class","Link_Internal");
}
/**/
} else if (eregi("^(http|https)+(:\/\/)+[a-z0-9_-]+\.+[a-z0-9_-]", $attuale )) {
$node->setAttribute("target","_blank");
$node->setAttribute("class","Link_External");
} else {
continue;
}
}
/* end link rewrite */
$xhtml = $dom->saveXML();
return $xhtml;
}
To copy to clipboard, switch view to plain text mode
Bookmarks