Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

How to parse XML file using CParser class


Reviewer Approved    
The following example shows how to parse XML file using Symbian OS C++ class, CParser. CParser is basically a SAX (Simple API for XML)-based XML parser.
It uses an active object to read the XML file chunk by chunk (see CXmlHandler::StartParsingWithAoL() method). On each chunk, it passes the buffer to the XML parser. When the XML parser finds an element, it calls the respective callback functions, for example CXmlHandler::OnStartElementL() or CXmlHandler::OnEndElementL().
To use CParser class, the XmlFramework.lib has to be included in the .mmp file. For more information about CParser, please visit some links at the end of this page.
Contents
[hide]
 1 XmlHandler.h
 2 XmlHandler.cpp
 3 download example
 4 See Also
[edit] XmlHandler.h
#ifndef __XMLHANDLER_H__
#define __XMLHANDLER_H__
 
// INCLUDE FILES
#include <e32base.h>
#include <f32file.h>  //Link against efsrv.lib
#include <xml\contenthandler.h> // for MContentHandler
#include <xml\parser.h> // for CParser
 
// CLASS DECLARATION
 
using namespace Xml;
 
class CXmlHandler: public CActive, MContentHandler
    {
 
public: // Constructors and destructor
 
    static CXmlHandler* NewL();
 
    static CXmlHandler* NewLC();
 
    virtual ~CXmlHandler();
 
public: // Public methods
 
    void StartParsingWithAoL( const TDesC& aFileName );
 
private: // Constructors
 
    CXmlHandler();
 
    void ConstructL();
 
private: // from CActive
 
    void DoCancel();
 
    void RunL();
 
private: // from MContentHandler
 
    void OnStartDocumentL( const RDocumentParameters &aDocParam,
  &n


Ïà¹ØÎĵµ£º

ÓÃphp¶ÁÈ¡xmlÊý¾Ý


½ñÌ칤×÷ÉÏÅöµ½Ò»¸öÎÊÌâ ÓÉÓÚÎÒÃǵÄÏîÄ¿Êý¾ÝÌ«ÉÙ ËùÒÔÐèÒª´Óweb searchÄDZ߽èµ÷Êý¾Ý£¬ËûÃÇÖ»¸øÎÒÃÇÌṩÁËÒ»¸öxmlµÄ½Ó¿Ú¡£Òò´Ë£¬ÎÒÃÇÐèÒª°ÑxmlµÄÊý¾Ýת»¯³Éhtml³ÊÏÖ¸ø´ó¼Ò¡£ÓÉÓÚÏîÄ¿ÊÇ»ùÓÚphpµÄ£¬ËùÒÔ¾ÍÞðÆúÁËÓÃjsÀ´¶ÁÈ¡xmlÑ¡ÔñÁ˼ÌÐøÊ¹ÓÃphp¡£²»¹ý£¬ÎÒÒÔǰ´ÓÀ´Ã»ÓÐ×ö¹ý´ËÀàµÄ³¢ÊÔ ËùÒÔÕÒÁ˺ܶàÍøÉÏ×ÊÁÏͬʱ²ÎÕÕÁËphpµÄ¹¤× ......

JSPÁªÏµXMLÓëÊý¾Ý¿â

  Êý¾Ý¿âÓ¦ÓÃϵͳ°üÀ¨Êý¾Ý¿â£¬Êý¾Ý¿â¹ÜÀíϵͳ£¬Êý¾Ý¿âÓ¦ÓÃÈý´ó²¿·Ö¡£
  ÊÀ½çÉÏ´æÔÚÐí¶àÍêÈ«²»Í¬µÄ¿Í»§Æ½Ì¨£¬ÔÚ²»Í¬Æ½Ì¨¼ä½»»»Êý¾Ý£¬ÐèÒª±£Ö¤Êý¾ÝµÄÍêÕûºÍ·þÎñµÄ¸ßЧ£¬Êý¾Ý¸ñʽµÄת»»ÎÊÌâÍùÍù³ÉÎªÖÆÔ¼Web ServiceµÄÆ¿¾±£¬²ÉÓÃXML×÷ΪÊý¾Ý½»»»µÄ±ê×¼£¬¿ÉÒÔʹ¸÷¸öÒ칹ƽ̨ºÍ¸÷ÖÖ¸ñʽµÄÊý¾Ý½øÐÐÊý¾Ý½»»»³ÉΪ¿ÉÄÜ¡£
......

ÓÃCMarkUpÀà½âÎöXMLÎļþ

½âÎö£º
 CMarkup xml;
 CString strChanText, strChanType;
 xml.Load("MyXml.xml");
 xml.ResetMainPos();
 if (!Chan.FindElem("TreeOrg"))
 {
      return;
 }
 if (xml.IntoElem())
 {
      xml.FindEle ......

½»»»Êý¾Ýѧϰһ£º½«xmlÎı¾¶ÁÈ¡µ½DataSet²¢ÏÔʾ

//xmlÎĵµÄÚÈÝ
<?xml version = "1.0" encoding="gb2312" standalone="yes"?>
<VFPData>
 <company>
  <companyno>100</companyno>
  <companyname>ÉϺ£</companyname>
  <ceoname>³ÂËÄ</ceoname>
  <ceoma ......

DataSet ¶ÁÈ¡xmlÎļþ

 DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(NetShop.Config.DbConfigs.GetSitePath + "images/flashdata/flash.config"));
DataRow[] drs = ds.Tables[0].Select("", "[SortOrder] ASC");
//·µ»ØµÄÊǸöDataRow[]£º
//DataR ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ