My next question was regarding what you called a ChainedXPath, but I was
thinking of more of a
tunneling effect.  My application basically reads in id3v2 tags from mp3
files and makes an
xml file containing all relevant information.  I then use XSL to transform
this into many static pages
for display in a browser.  My previous problem was that I had to write code
for each level in my document.
I first check for the artist and create it if not found, then the album and
create it if not found, and
then finally the tract which I also create if not found.  What I am looking
for or looking to create is a tool
that will add any node into an existing and only create nodes when they are
not found.  Does anyone know of a tool
that can do this.

Example:

"CD_Library/artist[@name=$artist]/album[@title=$album]/tract[@title=$tract]"

This would look for the artist and create if not found....all the way down
to the tract.

Thanks for your time,

Jason Long
JML Internet Enterprises - www.jmlie.com
BS Physics, MS Chemical Engineering

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of bob
mcwhirter
Sent: Thursday, November 01, 2001 3:01 PM
To: Jason Long
Cc: [EMAIL PROTECTED]
Subject: RE: [Jaxen] Escaping ' and " in xpath strings


> Here is a sample of code I was using before that also works when a ' is
> replaced with `.

Yah, cause a backtick isn't magical in the world of XPath.  It's just
another
byte, basically.  Single- and double-quotes delimit string literals.  In
your original example, you're creating a single-quote string literal as the
attribute value.  If instead you did double-quote string literals, then
things with single-quotes would pass just fine:

        new XPath( "CD/artist[@name=\"" + artist + "\"]" );

Of course, that would then flake out on anything with a double-quote in
the value.

> Here is the fix to my problem.  It properly handles ' in names of the
> strings set in the SimpleVariableContext.  Will this work for other
> characters that might invalidate xpath syntax?

Yes, because all of the problems you've seen so far occur at the
lexical level.  Using $variable notation, you're bypassing the lexer
with your value.  That value only gets dealt with at evaluation
time, and *not* at lex-time.  The lexer only sees "$variable" which
is always legal.  You should see no problem even if you set
$artist to the string "foo/bar<baz>&lt;cheese@'\"".  It's opaque,
and is never lexed.

>     XPath xpathArtist = new XPath(strXPathArtist);
>     XPath xpathAlbum  = new XPath(strXPathAlbum);
>     XPath xpathTract  = new XPath(strXPathTract);
>
>     xpathArtist.setVariableContext(variables);
>     xpathAlbum.setVariableContext(variables);
>     xpathTract.setVariableContext(variables);

This looks like a good candidate for someone to write a ChainedXPath
container, or something.

        XPath xpathArtist = new ChainedXPath( strXPathArtist );

        XPath xpathAlbum = xpathArtist.append( "album[@title=$album]" );

        XPath xpathTrack = xpathAlbum.append( "track[@title=$track]" );

Of course, that'd just evaluate each segment in order, using the
results as the context of the next link in the chain.  Might be
sub-optimal.

        -bob



_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to