1 Star 0 Fork 0

绫零依 / MyXMLParser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

QSimpleXMLParser

一个简单的、小的、并不高效、可能也不易用的XML解析器。大量借鉴了TinyXML-2

特点与坑

  • 仅支持ASCII和UTF-8。
  • 递归地进行解析。
  • 没有很好的组织内存,每个节点独自被new,比较松散。未来可以加入TinyXML-2那样的内存池。
  • 元素的属性没有当作节点处理。
  • 不处理Declaration,单纯读入其内容。
  • 子节点以链表组织,不支持子节点的随机访问。
  • 接口不是很合理。

使用示例

从文件中读取XML,并解析

    XMLDocument doc;
    doc.loadFile("test.xml");

访问DOM树

    XMLNode* node1 = doc.firstChild();
    for(XMLNode* p = node1; p != nullptr; p = p->nextSibling()){
        cout<<node1.getValue()<<endl;
    }

    node1.addLastChild(new XMLText("Test"));

    delete node1.firstChild();
    
    node1.removeFirstChild();

将DOM打印为XML文档

    XMLPrinter printer(std::cout);
    doc.accept(printer);

QSimpleXMLParser

A simply, small, inefficient, and probably unusable XML parser. Borrowed many things from TinyXML-2.

Feature and Flaws

  • Only support ASCII and UTF-8.
  • Parse xml recusively.
  • Memory management is not well. Every node object is newed standalone. Maybe implement memory pool like TinyXML-2.
  • Attributes of elements are not treaded treated as nodes.
  • Declaration will not be process. Only store its content.
  • Children of a node are originzed by a link list.
  • The interfaces may be not desirable.

Example Usages

Read XML from file and parse it.

    XMLDocument doc;
    doc.loadFile("test.xml");

Visit the DOM tree.

    XMLNode* node1 = doc.firstChild();
    for(XMLNode* p = node1; p != nullptr; p = p->nextSibling()){
        cout<<node1.getValue()<<endl;
    }

    node1.addLastChild(new XMLText("Test"));

    delete node1.firstChild();
    
    node1.removeFirstChild();

Print DOM as XML document.

    XMLPrinter printer(std::cout);
    doc.accept(printer);

空文件

简介

A XML Parser. 展开 收起
C++
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/qiao712/MyXMLParser.git
git@gitee.com:qiao712/MyXMLParser.git
qiao712
MyXMLParser
MyXMLParser
master

搜索帮助