void TextBlockMainWindow::readXMLDoc(const QString path)
{
QFile file(path);
//判断是否打开
if(file.open(QIODecice::ReadOnly|QFile::Text))
{
QDomDocument doc;
doc.setContent(&file);
QDomElement rootNode = doc.documentElement();//读取根节点
QString rootNodeName = rootNode.tagName();
qDebug()<<rootNodeName;
parseAllMembers(rootNode);
}
}
//遍历子节点
void TextBlockMainWindow::parseAllMembers(const QDomElement &rootNode)
{
QDomNode PDFirstNode =rootNode.firstChild();//第一个孩子节点 pD0
int i = 0,j = 0,k =0;
if(!PDFirstNode.isNull())
{
while(!PDFirstNode.isNull())
{
QDomNode PDFirstNodeChild = PDFirstNode.firstChild();//第一个孩子,子节点
QDomNode PDFirstNodeGrandChild = PDFirstNodeChild.firstChild();//孙子节点
if(!PDFirstNodeChild .isNull())
{
while(!PDFirstNodeGrandChild.isNull())
{
qDebug()<<PDFirstNodeGrandChild.toElement().tagName();
PDFirstNodeGrandChild = PDFirstNodeGrandChild.nextSibling();
}
}
}
PDFirstNode = PDFirstNode.nextSibling();
}
}