Search code examples
javaxmlxpathstreamsax

XML Stream XPath Processor Algorithm


I am developing XML Stream XPath Processor in java, What i am expecting to do is

1.) Split the Xpath into elements and store the elements in a queue.

2.) Go through the XML file by SAX and in it's startElement() method check the current element is in the queue.

3.) If it is in the queue, then store the element data in characters(...) method.

Is my approach correct? I am stuck in first step because, it is hard to check all the xPath commands to divide the elements. Is there is any easy way to implement first step?


Solution

  • If you define a simple subset of XPath, for example

    ("/" name ( "[" integer "]" )? )*
    

    Then parsing it isn't very difficult, and matching it against the events in a SAX stream isn't very difficult either. (Though namespaces are always a challenge).

    But the way you have phrased the question makes me suspect that even this simplified problem requires more experience and/or computer science knowledge than you currently possess: the fact that you are already asking questions like this suggests to me that you don't have any idea of the scale of the challenge you have set yourself.