Use the XML Parser in OS 9.x
来源:互联网 发布:淘宝客服介入怎么判定 编辑:程序博客网 时间:2024/05/09 21:39
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 as ASCII. Most of the parameters are RStrings, which mean that from the RString class you need to call DesC() which returns the TDesC8& representing the token text.
For example in the OnStartElementL function, you will have a parameter of type RTagInfo which contains the Local name, prefix and uri RStrings. So if the parameter is called aElement, then to get the name of the element you will need to do this:
const TDesC8& elementName = aElement.LocalName().DesC();
This returns the TDesC8 which holds the name of the element which you can use.
S60, Symbian C++ | Next | Previous | Comments (4) | Trackbacks (0)
- Use the XML Parser in OS 9.x
- Mac OS X:Analysis of the Use of the Boot Server Discovery Protocol in NetBoot
- Example Code of Using XML Parser in Symbian OS
- The Expat XML Parser
- How to use dylib in Mac OS X
- A few notes about the CommDb (use in Symbian OS)
- The following macros are predefined in OS X:
- Clear the “Open With” menu in Mac OS X
- How to use Oracle Instant Client in Mac OS X Lion
- MAC OS X中解决SOCKET.ERROR: [ERRNO 48] ADDRESS ALREADY IN USE 端口占用问题
- Mac OS X中解决java.net.BindException: Address already in use 端口占用问题
- Using the Windows Forms XML Parser Sample
- libxml2, the XML C parser and toolkit
- How to use libusb1.0 library to develop the application on Mac OS X
- How to Use Docker on OS X: The Missing Guide (杂译)
- Use MySQL on Mac OS X
- Use Dojo in the ZF
- XML PARSER
- workflow activity introduction
- Javadoc
- socket connect函数理解
- How to parse XML file using CParser class
- how to apply sepia to photo on iphone
- Use the XML Parser in OS 9.x
- 思考
- windows平台下的netbeans开发C++,以及常见问题的解决
- delphi排课系统毕业设计论文
- Linux编程:getopt_long及其使用
- Example Code of Using XML Parser in Symbian OS
- 字符集之间转换(UTF-8,UNICODE,Gb2312)
- ERDAS IMAGINE 9.0 (遥感图像处理):
- 分页技巧