Hi,
How about this xml document. Do you have any idea how to parse it using QXml StreamReader or QDomDocument??
<p>
There are two types of hydraulic tools for the connecting rod shank screws, see
<ref xml:link="simple" inline="true" behavior="external" content-role="fig" href="fig-400731-low">Fig 07-20</ref>
. The screws and nuts in the tool of
<hp0>new design</hp0>
(introduced in year 2001) should be replaced before reaching
<hp0>1000</hp0>
loading cycles, i.e raising the pressure to nominal value 1000 times).
</p>
Any help please. I have to read all of them.
I am using things like this:
QString content=reader.readElementText(QXmlStreamReader::I ncludeChildElements);
it will include everything inside <p> tag including those ref hp0. Then, I will go back to the beginning of <p> tag and readNext() to read the attribute and value <ref> and <hp0> tag.
while(!reader.isEndElement()||reader.name()!="p"){
if(reader.isStartElement()){
if(reader.name()=="ref"){
QString displaytext=reader.readElementText();
QXmlStreamAttributes attrs = reader.attributes();
QString role=attrs.value("content-role").toString();
QString href=attrs.value("href").toString();
QString link="<a href=\""+role+";"+href+"\">["+displaytext+"]</a>";
value.replace(displaytext,link);
}else if(reader.name()=="hp0"){
QString bold=reader.readElementText();
int bindex=value.indexOf(bold);
if(bindex!=-1&&value.indexOf("<b>"+bold+"</b>")==-1){
value.replace(bindex,bold.length(),"<b>"+bold+"</b>");
}
}else{
qDebug()<<"error. Undefined tag name inside <p>";
qDebug()<<reader.name();
}
}
reader.readNext();
}
HOWEVER, my big and funny problem is that with QXmlStreamReader we dont have the option to roll back to previous start tag. In this case when I use
QString content=reader.readElementText(QXmlStreamReader::I ncludeChildElements);
the current cursor is at the end of tab </p> and I can not roll back to the beginning of <p> tag to read <fig> and <hp0> tag
Any help please.
Bookmarks