Re: SAX-based XPath



Gary Shea wrote:
> I'm posting this in hope of getting some API suggestions.
>
> I'm building a native stream-based Ruby XPath processor (or whatever
> it would be called) in order to parse some gigabyte-scale XML files at
> work. It will accept multiple XPath expressions and output events
> (SAX for now) matching the union of the XPath expressions.
>
> It currently only works with absolute, non-wildcarded, predicate-less
> default-axis XPath expressions:
>
> filter = XmlFilter::XPathFilter.new
> filter.listener = XmlFilter::RecordingListener.new
> filter.xpath = '/a/b/c'
>
> parser =
> REXML::Parsers::SAX2Parser.new(File.open('some_file_path.xml'))
> parser.listen = filter
> parser.parse
>
> This interface needs to be extended a little to work with multiple
> XPath expressions, maybe:
>
> filter.xpath = ['/a/b/c', '/d/e/f']
>
> Any suggestions for a more Ruby-esque way to do it?

It seems you could simplify the interface a bit (or add a method) along
the lines of REXML so you can do

File.open('some_file_path.xml') do |io|
XmlFilter::XPathFilter.parse(io, '/a/b/c', '/d/e/f') do |event, filter|
# process event
end
end

I'm unsure about the "filter" block parameter but it might be useful to
know the matching filter criterium. What do you think?

Kind regards

robert




.



Relevant Pages

  • Re: XPath speed.
    ... However, there are plans afoot to use the code to do something a lot more performance-critical, and so if XPath queries prove to be a significant part of the workload, easy speedups would be good to know about. ... My XPath expressions (as Strings) were all being injected by Spring into one of my beans. ... ./Tag or /Tag or Tag ... I imagine you could implement XPath expressions by code generation, ...
    (comp.lang.java.programmer)
  • Re: xml Signature and XmlDsigXPathTransform
    ... J-P, Merlin - ... in XPath expressions you are supplying to XmlDSig classes you should use the ...
    (microsoft.public.dotnet.security)
  • Re: Accessing HTML DOM from cscript.exe
    ... If you have mastered XPath expressions then I bow before you. ... If XMLDOM works for the particular HTML documents you're trying to parse, ... Can I use XPath expressions to find nodes in an HTML ...
    (microsoft.public.scripting.jscript)
  • Re: xml Signature and XmlDsigXPathTransform
    ... I am not expert in XPath expressions, ... XmlDSigXPathTransform didn't make the tranformation as I expected it to do ... Dim signedXml As New SignedXml ...
    (microsoft.public.dotnet.security)
  • SAX-based XPath
    ... I'm building a native stream-based Ruby XPath processor (or whatever it ... It will accept multiple XPath expressions and output events (SAX ... filter = XmlFilter::XPathFilter.new ... This interface needs to be extended a little to work with multiple XPath ...
    (comp.lang.ruby)