PDA

View Full Version : Getting All Text Between Tags in XML ?



seanmu13
8th June 2007, 16:08
Lets say the xml file looks like:


<article>
<title>Help</title>
<abstract>
<p>First pgraph.</p>
<p>Second pgraph</p>
</abstract>
</article>

and I want to extract everything (data as well as tags) between the abstract tags so I could put that in a string. The thing I extract would then be:



<p>First pgraph.</p>
<p>Second pgraph</p>


Anybody know how to do this?

patrik08
8th June 2007, 17:29
Lets say the xml file looks like:
[CODE]
<article>
<title>Help</title>
<abstract>
<p>First pgraph.</p>
<p>Second pgraph</p>
</abstract>
</article>
ow to do this?


get the dom from abstract and create a new QDomDocument and catch as QString xml_xhtml = mdoc1.toString();

this sample fill 6 qtextedit on a tab from a loop <page language="en"> on 6 language ....






QDomElement xpage = root.firstChildElement("page");
while (!xpage.isNull()) {
QDomElement edomactual = xpage;
QString hla = doc.GetAtt(xpage,"human"); /* humanlanguage string */
QString xla = doc.GetAtt(xpage,"la"); /* iso browser language string 2 size */
///////////qDebug() << "### xmlloop " << xla;
bodyxhtml = xpage.firstChildElement("body");
htmldiv = bodyxhtml.firstChildElement("div");
QDomDocument mdoc1;
html = mdoc1.createElement("body");
html.setAttribute ("BGCOLOR",BGCOLORPAGES);
html.setAttribute ("style","la="+xla);
html.appendChild( htmldiv );
mdoc1.appendChild( html );
QString xml_xhtml = mdoc1.toString();
xml_xhtml = xml_xhtml.replace("<div class=\"qtpage\" xmlns=\"http://www.w3.org/1999/xhtml\" >","");
xml_xhtml = xml_xhtml.replace("</div>","");
xml_xhtml = xml_xhtml.replace(QString("src=\"./"),QString("src=\"%1").arg(Work_imcache),Qt::CaseInsensitive);
xml_xhtml = xml_xhtml.replace(QString("src=\"/%1").arg(ServerPath),QString("src=\"%1").arg(Work_imcache),Qt::CaseInsensitive);

QString prehtml ="<html><head><meta name=\"qrichtext\" content=\"1\" />"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
"<style type=\"text/css\">"
"p, li { white-space: pre-wrap; } "
"</style></head>";