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

Use the XML Parser in OS 9.x


Paul.Todd | 09 April, 2007 15:24
I have noticed a couple of people seem to be having problems with using the XML parser in Symbian and there are no examples outside of the devkit. The parser I will be talking about is the xml one, not the one SOAP engine as the SOAP one is Nokia specific.
The key to parsing XML is to understand how SAX based parsing works.
The key to using the Symbian XML API is to understand how SAX works and how its been implemented in Symbian.
SAX is at its core an event driven model that supports data being streamed, making it ideal for devices.
The foundation of the parser is the MContentHandler class which provides the callback interface you need to implement. In fact the first thing you need to do is to create a class deriving from MContentHandler that implements all of the pure virtual methods of MContentHandler
You can then create a CParser class and use your implementation of MContentHandler to provide the call backs required. You will normally only use "text/xml" for the mime type. You can then pass your XML over to the Parse functions for parsing. by calling ParseBegin, ParseL and ParseEnd. For the most part you can just use the Xml::ParseL functions to parse files and text.
What happens when you call ParseL is that as the document is parsed and an "event" is identified, be it an element, comment, document processing instruction or plain data is encountered, the relevant callback is called and your code is executed, it is up to you to handle the data.
Normally for simple XML you will just worry about the OnBeginElementL,  OnEndElementL and OnContentL. It is up to you to handle nested elements.
Note that the OnContentL method can be called multiple times and is only considered complete when OnEndElementL is called so its up to you to store intermediate content passed in each time ContentL is called.
Also can be a bit strange that the data is all in ASCII (UTF8 IIRC) and so you need to convert it to unicode or handle it


Ïà¹ØÎĵµ£º

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


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

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

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

JavaScript ¶ÁÈ¡ XMLÎļþ

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<mce:style type="text/css"><!--

table,tr,td {
background-position: center;
border-width: 1px;
border-style: solid;
border-coll ......

Symbianѧϰ±Ê¼Ç(15) ½âÎöXMLÎļþ(ÉÏ)

ÊÕ²Ø
ÎÒÔøÔÚÇ°Ãæ½éÉܹýÒ»¸ö¿ÉÓÃÓÚBREW»·¾³ÏµÄXML Parser£¬½ñÌìÏë·ÖÏíµÄÊÇÈçºÎÔÚSymbianƽ̨ÉϽâÎöXMLÎļþ£¬²»ÐèÒªµÚÈý·½µÄ¶«Î÷£¬SymbianÒѾ­ÎªÎÒÃÇÌṩÁËÕâ¸öÀàCParser¡£
ÍøÉÏÒ²ÓÐÕâ·½ÃæµÄ×ÊÁÏ£¬½¨Òé²Î¿¼£º
http://wiki.forum.nokia.com/index.php/How_to_parse_XML_file_using_CParser_class
²»¹ý£¬Òª×¢ÒâµÄÊÇSymbia ......

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( ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ