Qt 中 QXml/QDom*** api设计吐槽

昨天下午搞了一下Qt中的dom解析。发现并没有java中的好用。

1. 除了QDomDocument类以外,均没有toString方法。我仅仅想吧QDom**->QString 只能通过QDomDocuemnt来实现

2. 就算用QDomDocument。 需要将QDom** append到QDomDocument。就会出现下面的结果:

    QDom**是通过此QDomDocument::create**出来的。可以append.

    QDom**不是通过此QDomDocument::create**出来的,QDomDocument用带参的初始化方法初始化的。可以append

    QDom**不是通过此QDomDocument::create**出来的,QDomDocument用无参的初始化方法初始化的。不可以append

3. QDomNode是所有QDom**的父类。其中appendChild()又是我们经常用的。看官网注释

Appends newChild as the node's last child.

If newChild is the child of another node, it is reparented to this node. If newChild is a child of this node, then its position in the list of children is changed.

If newChild is a QDomDocumentFragment, then the children of the fragment are removed from the fragment and appended.

If newChild is a QDomElement and this node is a QDomDocument that already has an element node as a child, newChild is not added as a child and a null node is returned.

Returns a new reference to newChild on success or a null node on failure.

Calling this function on a null node(created, for example, with the default constructor) does nothing and returns a null node.

The DOM specification disallow inserting attribute nodes, but for historical reasons, QDom accepts them anyway.

  1. 如果newChild是其他节点的孩子,那么重定向到此节点,如果是这个节点的孩子,则改变位置。

    如果我仅仅想复制newChild到其他节点。那么我需要copy newChild,比较蛋疼需要重新new一个然后一个一个copy。

    ok 我知道写个clone方法或者有api可以调用。但是增加一个直接插入的函数难道不好么?我帮起个名字:appendChildFocus();

     2. 3. 就不说了。也是限制条件。 

 

 我只关注了这些。浪费了我4个小时的时间后,然后决定用QJson OYE. 

 google了一下大家怎么评论的。第一条就是" just confusing me!!!"  所以建议大家能不用QDom就不用。

 

posted @ 2013-09-23 12:18  wFeng  阅读(1698)  评论(0编辑  收藏  举报