QTÖÐʹÓÃQXmlStreamReader½âÎöXMLÎļþ
XMLÎļþÓÉÓÚÆäÀ©Õ¹ÐÔÓë¼æÈÝÐÔµÄÓŵ㣬±»¹ã·ºÓÃ×÷Èí¼þºÍϵͳµÄÅäÖÃÎļþ¡£ÕâÀï¼òÒª½éÉÜÒ»ÏÂQTÏÂÈçºÎÀ´½âÎöXMLÎļþ¡£
Ô´´úÂ룺
xml_reader.h
#ifndef XML_READER_H
#define XML_READER_H
#include <QtCore>
//#include <QtGui>
class xml_reader : public QXmlStreamReader
{
//Q_OBJECT
public:
xml_reader();
bool read(QIODevice *device);
private:
void read_data();
void read_startweek();
void read_eventnumber();
void read_period();
void read_id();
void read_starttime();
void read_endtime();
void read_exception();
void read_subexception();
void read_description();
void read_duration();
void read_event();
void read_offsettime();
void read_eventdesc();
void read_eventname();
void read_prompt();
void read_lasthandle();
void read_unknow();
};
#endif // XML_READER_H
xml_reader.cpp
#include "xml_reader.h"
xml_reader::xml_reader()
{}
bool xml_reader::read(QIODevice *device)
{
setDevice(device);
while(!atEnd())
{
readNext();
if(isStartElement())
{
if(name() == "data")
{
read_data();
}
}
}
return !error();
}
void xml_reader::read_data()
{
qDebug()<<"Start to read data...";
while(!atEnd())
{
readNext();
if(isStartElement())
{
if(name() == "period")
{
read_period();
}
if(name() == "startweek")
{
read_startweek();
}
if(name() == "eventnumber")
{
read_eventnumber();
}
}
if(isEndElement())
{
if(name() == "data")
{
qDebug()<<"Now at the end of data element...";
break;
}
}
}
}
void xml_reader::read_startweek()
{
Ïà¹ØÎĵµ£º
ËùÓÐ XML ÎĵµÖеÄÎı¾¾ù»á±»½âÎöÆ÷½âÎö¡£
Ö»ÓÐ CDATA Çø¶Î£¨CDATA section£©ÖеÄÎı¾»á±»½âÎöÆ÷ºöÂÔ¡£
Parsed Data
XML ½âÎöÆ÷ͨ³£»á½âÎö XML ÎĵµÖÐËùÓеÄÎı¾¡£
µ±Ä³¸ö XML ÔªËر»½âÎöʱ£¬Æä±êÇ©Ö®¼äµÄÎı¾Ò²»á±»½âÎö£º
<message>´ËÎı¾Ò²»á±»½âÎö</message>
½âÎöÆ÷Ö®ËùÒÔÕâô×öÊÇÒòΪ XML ÔªËØ¿É°ü ......
xml£º
<?xml version="1.0" encoding="utf-8" ?>
<library>
<name>Ê׶¼Í¼Êé¹Ý</name>
<address>³¯ÑôÇø»ªÍþÇÅÄÏ</address>
<books>
<book type="math">
<id>0000</id>
</book&g ......
FlashÖеÄXML¶ÔÏóÒ²Óз½·¨¿ÉÒÔ½«XMLÊý¾ÝÏò·þÎñÆ÷·¢ËÍ¡£¼´sendºÍsendAndLoad¡£send·½·¨Ïòij¸ö URL ´«µÝ XML ¶ÔÏ󣬷µ»ØµÄÐÅÏ¢¶¼±»·¢Ë͵½ÁíÍâÒ»¸öä¯ÀÀÆ÷´°¿Ú£»sendAndLoad ·½·¨Ïòij¸ö URL ·¢ËÍÒ»¸ö XML ¶ÔÏó¡£·µ»ØµÄÐÅÏ¢¶¼·ÅÔÚÒ»¸öXML¶ÔÏóÖС£
ÔÚijÖ̶ֳÈÉÏ£¬ XMLµÄsend·½·¨ºÍsendAndLoad·½·¨ÀàËÆÓÚloadVars¶ÔÏóµÄsend·½·¨ºÍ ......
JAXB¸ÅÒª
JAXBΪJava Architecture for XML BindingµÄËõд£¬ÒâΪXML°ó¶¨µÄJAVA¿ò¼Ü¡£ËüÌṩÁËÒ»Ì׿ÉÒÔ¼òµ¥´æÈ¡XMLÊý¾ÝµÄAPI£¬Í¬Ê±£¬JAXB¿ÉÒÔ¸ù¾ÝXMLµÄschema×Ô¶¯Éú³É²Ù×÷XMLµÄJAVAÀà¡£ÀûÓÃJAXB£¬Ê¹ÓÃJAXB×Ô¶¯Éú³ÉµÄ²Ù×÷XMLµÄJAVAÀ࣬¿ÉÒÔ»ù±¾Éϲ»Óÿ¼ÂÇXML½á¹¹¶ø¼òµ¥µØ´æÈ¡XMLÊý¾Ý¡£
JAXBµÄÏÂÔØÓë°²×°
JAXBÖÁÉÙÐèÒªµ¼ÈëÒ ......