Qt模块化笔记之core——QXmlStreamReader的几个函数返回值类
来源:互联网 发布:js file读取文件路径 编辑:程序博客网 时间:2024/04/29 21:00
本文主要讨论QXmlStreamReader的几个函数返回值所涉及的类、
QXmlStreamReader的函数为:
QXmlStreamAttributesattributes() constQXmlStreamEntityDeclarationsentityDeclarations() constQXmlStreamEntityResolver *entityResolver() constQXmlStreamNamespaceDeclarationsnamespaceDeclarations() constQXmlStreamNotationDeclarationsnotationDeclarations() const
————————————————————————————————————————————————————————————
1, QXmlStreamNamespaceDeclaration和QXmlStreamNamespaceDeclarations
两个类都有关“XML流的命名空间声明”,关系为(The QXmlStreamNamespaceDeclarations class is defined to be a QVector of QXmlStreamNamespaceDeclaration.)
QXmlStreamNamespaceDeclarations QXmlStreamReader::namespaceDeclarations() const上面这个函数,如果 tokenType()为StartElement,则它返回“XML流的命名空间声明”,否则,空的vector返回。
为本函数准备的XML代码为:
<?xml version="1.0" encoding="UTF-8"?> <tables> <table xmlns:h="http://www.w3.org/TR/html4/"> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> <table xmlns:f="http://www.w3school.com.cn/furniture"> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> </tables>测试C++代码为:
#include "dialog.h"#include "ui_dialog.h"#include <QFile>#include <QIODevice>#include <QDebug>#include <QXmlStreamNamespaceDeclarations>Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog){ ui->setupUi(this); QFile *file=new QFile("://test2.xml"); if(!file->open(QIODevice::ReadOnly)) { qDebug()<<"文件打开失败"; return; } xmlReader =new QXmlStreamReader(file); while(!xmlReader->atEnd() && !xmlReader->hasError()) { xmlReader->readNext(); if(xmlReader->tokenType()==QXmlStreamReader::StartElement) { QXmlStreamNamespaceDeclarations ns=xmlReader->namespaceDeclarations(); foreach (QXmlStreamNamespaceDeclaration n, ns) { qDebug()<<n.prefix()<<" "<<n.namespaceUri(); qDebug()<<"——————"; } } }}Dialog::~Dialog(){ delete ui;}输出为:
"h" "http://www.w3.org/TR/html4/"
——————
"f" "http://www.w3school.com.cn/furniture"
——————
————————————————————————————————————————————————————————————
2,QXmlStreamEntityDeclarations与QXmlStreamEntityDeclaration关系与上述相同
QXmlStreamEntityDeclarationsentityDeclarations() const如果 tokenType()是DTD,返回的是未解析的原实体声明,即整个:
<!DOCTYPE Notes [ <!ELEMENT note (date,message)> <!ELEMENT date (#PCDATA)> <!ELEMENT message (#PCDATA)> ]>否则是个空的vector
QXmlStreamEntityDeclaration公有函数有:
QXmlStreamEntityDeclaration()QXmlStreamEntityDeclaration(const QXmlStreamEntityDeclaration & other)~QXmlStreamEntityDeclaration()QStringRefname() constQStringRefnotationName() constQStringRefvalue() constQStringRefpublicId() constQStringRefsystemId() constbooloperator!=(const QXmlStreamEntityDeclaration & other) constQXmlStreamEntityDeclaration &operator=(const QXmlStreamEntityDeclaration & other)booloperator==(const QXmlStreamEntityDeclaration & other) const测试的XML代码如下:
<?xml version="1.0"?><!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>]><note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body></note>
qt代码如下:
#include "dialog.h"#include "ui_dialog.h"#include <QFile>#include <QIODevice>#include <QDebug>#include <QXmlStreamNamespaceDeclarations>#include <QXmlStreamEntityDeclarations>#include <QXmlStreamEntityDeclaration>Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog){ ui->setupUi(this); //—————————————————————— QFile *file2=new QFile("://test3.xml"); if(!file2->open(QIODevice::ReadOnly)) { qDebug()<<"文件打开失败"; return; } xmlReader2 =new QXmlStreamReader(file2); while(!xmlReader2->atEnd() && !xmlReader2->hasError()) { if(xmlReader2->readNext()==QXmlStreamReader::DTD) { QXmlStreamEntityDeclarations ns=xmlReader2->entityDeclarations();// foreach (QXmlStreamEntityDeclaration n, ns) {// qDebug()<<"行:"<<n.name()<<n.notationName()<<n.publicId()<<n.systemId()<<n.value();// } QVectorIterator<QXmlStreamEntityDeclaration> it(ns); while (it.hasNext()) { QXmlStreamEntityDeclaration n=it.next(); qDebug()<<"行:"<<n.name()<<n.notationName()<<n.publicId()<<n.systemId()<<n.value(); } } }}Dialog::~Dialog(){ delete ui;}
让我想不通,这里没输出……
————————————————————————————————————————————————————————————
未知功能,应该与这里有关:点击打开链接
————————————————————————————————————————————————————————————
4,QXmlStreamNotationDeclaration DTD标记声明
其公有函数如下:
QXmlStreamNotationDeclaration()QXmlStreamNotationDeclaration(const QXmlStreamNotationDeclaration & other)~QXmlStreamNotationDeclaration()QStringRefname() constQStringRefpublicId() constQStringRefsystemId() constbooloperator!=(const QXmlStreamNotationDeclaration & other) constQXmlStreamNotationDeclaration &operator=(const QXmlStreamNotationDeclaration & other)booloperator==(const QXmlStreamNotationDeclaration & other) const
————————————————————————————————————————————————————————————
本文较多漏洞,虚心求教……
0 0
- Qt模块化笔记之core——QXmlStreamReader的几个函数返回值类
- Qt模块化笔记之core——QXmlStreamReader的使用
- Qt模块化笔记之core——容器类归纳
- Qt模块化笔记之core——容器类归纳
- Qt模块化笔记之core——动画框架
- Qt模块化笔记之core——线程相关
- Qt模块化笔记之core——QXmlStreamWriter写XML
- Qt模块化笔记之core——事件QEvent
- Qt模块化笔记之Qt Widgets——日历类
- Qt模块化笔记之core——Input/Output文件操作(1)
- Qt模块化笔记之core——Input/Output文件操作(2)
- Qt模块化笔记之core——Input/Output文件操作(3)
- Qt模块化笔记之core——认识XML可扩展标记语言
- Qt模块化笔记之core——认识JSON,联系QJson
- Qt模块化笔记之core——使用QJsonDocument解析JSON
- Qt模块化笔记之core——使用QJsonDocument输出JSON数据
- Qt模块化笔记之core——使用信号与槽
- Qt模块化笔记之core——初窥状态机机制
- 离散极值
- Rightmost Digit
- I Think I Need a Houseboat
- spring之aop浅析
- 如何用Mac远程桌面连接windows
- Qt模块化笔记之core——QXmlStreamReader的几个函数返回值类
- cocos2d-x 利用CCLabelTTF制作文字描边与阴影效果的实现方法
- HTTPS通信建立过程
- 拨号上网、ISDN、ADSL、光纤上网比较
- Web API 设计
- 我的本科总结
- Regular Expression Matching
- 变量在内存中的存储位置
- C语言之define与typedef区别