⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlviewer.cxx

📁 基于网络编程的例子
💻 CXX
字号:
#include <stdlib.h>#include <iostream.h>#include <qapplication.h>#include <qwidget.h>#include <qdom.h>#include <qfile.h>#include <qtextstream.h>#include <qlistview.h>void traversenode(QDomNode &n, QListViewItem *parent){  QListViewItem *after=parent;  while(!n.isNull()) {    QListViewItem *parentptr=parent;    if(!n.isText())      parentptr=after=new QListViewItem(parentptr, after, n.nodeName());    if(!n.nodeValue().isNull())      parentptr=after=new QListViewItem(parentptr, after, n.nodeValue());    QDomNode child=n.firstChild();    if(!child.isNull())      traversenode(child,parentptr);    n=n.nextSibling();  }}int main (int argc, char *argv[]){  QApplication app(argc, argv);  if(argc<2) {    cout << "Usage: " << argv[0] << " <xmlfile>" << endl;    exit(-1);  }  QDomDocument doc("mydocument");  QFile f(argv[1]);  if(f.open(IO_ReadOnly)) {    QTextStream t(&f);    QString s;    while (!t.eof()) s.append(t.readLine());    doc.setContent(s);    f.close();  } else {    cout << "Couldn't open " << argv[1] << endl;    exit(-1);  }  QListView lv(0,argv[1]);  lv.addColumn("Data");  lv.setSorting (-1);  lv.setRootIsDecorated(TRUE);  QListViewItem lvi(&lv,"XML Data");  QDomNode child=doc.firstChild();  child=child.nextSibling();  traversenode(child,&lvi);  app.setMainWidget(&lv);  lv.show();  return app.exec();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -