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
相关文档:
标签:XML解析 TinyXML [推送到技术圈]
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://panpan.blog.51cto.com/489034/104961
最近使用TinyXML进行C++ XML解析,感觉使用起来比较简单,很容易上手,本文给出一个使用TinyXML进行XML解 ......
private void WriteXML()
{
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?> ");
sb.Append(" <!-- ");
sb.Append("<content>");
sb.Append(& ......
Xml, xslt, xsd, xpath描述一下
XML: Extensible Markup Language扩展标记语言,用来处理结构化文档。
XSLT: XSL Transformations。用来将一种XML转换成另外一种XML文档。也可以将XML转换成XHTML或者HTML在浏览器中显示。
XSD: XML Schemas Definition。用来定义XML文档的结构。XML Schema 是DTD(Document Type Definiti ......
解析:
CMarkup xml;
CString strChanText, strChanType;
xml.Load("MyXml.xml");
xml.ResetMainPos();
if (!Chan.FindElem("TreeOrg"))
{
return;
}
if (xml.IntoElem())
{
xml.FindEle ......
字号: 小 中 大 | 打印 发布: 2009-1-08 16:33 作者: webmaster 来源: 本站原创 查看: 40次
书接上回,这篇介绍那个MContentHandler的实现,这是SAX解析方法的核心所在。
先看看我要解析的XML文件如下所示,其实很简单,因为它除了Ele ......