kobjects / kxml2

Small XmlPull compatible parser
MIT License
41 stars 21 forks source link

Traversing the Parse Tree starting from a Node of TYPE != ELEMENT not possible. #18

Open everga opened 3 years ago

everga commented 3 years ago

Hello Stefan,

When using kxml2 to analyze "unknown" XML documents, I stumbled upon the fact that only nodes of the type ELEMENT are assigned their predecessors. So it is not possible to walk through the parse tree if the start point is not of type ELEMENT Wouldn't it be more sensible if elements of the type COMMENT and TEXT (possibly all) also get their predecessor. Should the memory requirement or the garbage collection be the reason for this decision perhaps using a weake reference for parrent could be the solution.

I hope I haven't overlook other side effects.

in Class: org.kxml2.kdom.Node.java at Method:

public void addChild(int index, int type, NodeInterface child) {
[...]
        if (type == ELEMENT) {
            if (!(child instanceof Element))
                throw new RuntimeException("TestElement obj expected)");

            ((Element) child).setParent(this);
        }
[...]
}

Thanks

Best wishes

Andreas