Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Re: relevant to the discussion we were having theother day

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Re: relevant to the discussion we were having theother day
  • Date: Thu, 23 Sep 2004 13:53:46 -0700

You can do such kind of things with XQuery. Since XQuery is a superset of XPath 2.0, it can also be used with plain XPath expressions as queries. Also note that XPath 2.0 supports regular expressions via the matches, replace, and tokenize functions.

For example:
// find the links of all images in a XHTML-like document
XQuery xquery = new XQuery("//img/@src", null);

// find the links of all JPG images in a XHTML-like document
// XQuery xquery = new XQuery("//img/@src[fn:matches(string(.), '.jpg')]", null);

Nodes nodes = xquery.evaluate(doc);
for (int i=0; i < nodes.size(); i++) {
System.out.println("node "+i+": "+nodes.get(i).toXML());
}

I'm working on XOM extensions for that. A working prototype is at

http://dsd.lbl.gov/~hoschek/xom-contrib-download

and javadoc is here:

http://dsd.lbl.gov/~hoschek/xom-contrib/

One can query some hundreds of 10K documents per second with that approach,
but in terms of performance it certainly cannot compete with a NodeFactory filter.
Rather, the primary motivation here is power with simplicity.

Wolfgang.

Elliotte, be brave and put some ideas down for us to see.
With your understanding of XML *and* developers, you
are one of the best positioned to do this.
It might be what makes XOM rock even more one day.
Add regexps to XPATH? or callbacks?
a new way to analyse XML which is more powerful
than regexps alone, but which doesn't turn entities
into landmines? be creative! go nuts!

Luca


> What Bray is suggesting here is a sort of XML-aware regular expression
> language. He very well understands that current regular-expression
> languages are inadequate for handling XML.
>
> One thing I have seen some people do is define a new, very inflexible
> syntax for XML infosets that resolves things like character entity
> references, insignificant white space, quotes around attribute values,
> and so forth; then write a program to convert XML documents into this
> new syntax; and then query the new syntax with regular expressions. It's
> a hack, but it works.
>
> In essence Bray is here proposing to build the alternate, less-flexible
> syntax into the regular expression engine. Perhaps a good idea, but it
> does need a new engine/language. The existing ones can't do this.


http://www.tbray.org/ongoing/When/200x/2003/03/16/XML-Prog

in particular notice the place where the guy does
(which is very close to what I was trying to do with
XOM):

while (<STDIN>) {
next if (X<meta>X);
if (X<h1>|<h2>|<h3>|<h4>X)
{ $divert = 'head'; }
elsif (X<img src="/^(.*\.jpg)$/i>X)
{ &proc_jpeg($1); }
# and so on...
}

Luca






Archive powered by MHonArc 2.6.24.

Top of Page