Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 7th, 2006, 09:15 PM
Yoav Shapira
Guest
 
Posts: n/a
Default XPath question: selecting content between two nodes

Hi,
I have a well-formed XHTML document that, among other content, has the
following segment:

<img src="uniqueUrl1" />
<p>some text</p>
<p>some other text</p>
<p>some more text</p>
<img src="uniqueUrl2" />

Now, my question: given unique URLs 1 and 2, how do I select all the
content between the two img nodes?

I thought //img[@src="uniqueUrl1"] would work for the first image and
//img[@src="uniqueUrl2"] for the second image node, but they don't seen
to, and anyways they don't give me the content between. I know of the
following axis, but not sure how to use it if it's applicable here at
all.

Any help would be appreciated -- thank you!

Yoav Shapira

  #2  
Old March 7th, 2006, 10:35 PM
Richard Tobin
Guest
 
Posts: n/a
Default Re: XPath question: selecting content between two nodes

In article <1141765206.022734.63800@j52g2000cwj.googlegroups. com>,
Yoav Shapira <yoavshapira@gmail.com> wrote:
[color=blue]
><img src="uniqueUrl1" />
><p>some text</p>
><p>some other text</p>
><p>some more text</p>
><img src="uniqueUrl2" />[/color]
[color=blue]
>Now, my question: given unique URLs 1 and 2, how do I select all the
>content between the two img nodes?[/color]
[color=blue]
>I thought //img[@src="uniqueUrl1"] would work for the first image and
>//img[@src="uniqueUrl2"] for the second image node, but they don't seen
>to[/color]

Well, I can't solve that problem, because those XPaths *do* select
the nodes in question! If it's not working for you, you are using them
wrongly.
[color=blue]
> and anyways they don't give me the content between. I know of the
>following axis, but not sure how to use it if it's applicable here at
>all.[/color]

Something like this will select the nodes between the two <img>
elements. It uses the following-sibling axis to get the sibling nodes
after the first <img>, and restricts them to the ones that have the
second <img> as a following-sibling.

//img[@src="uniqueUrl1"]/following-sibling::node()[following-sibling::img[@src="uniqueUrl2"]]

-- Richard
  #3  
Old March 7th, 2006, 10:45 PM
Johannes Koch
Guest
 
Posts: n/a
Default Re: XPath question: selecting content between two nodes

Yoav Shapira wrote:[color=blue]
> Hi,
> I have a well-formed XHTML document that, among other content, has the
> following segment:
>
> <img src="uniqueUrl1" />
> <p>some text</p>
> <p>some other text</p>
> <p>some more text</p>
> <img src="uniqueUrl2" />[/color]
[...][color=blue]
> I thought //img[@src="uniqueUrl1"] would work for the first image and
> //img[@src="uniqueUrl2"] for the second image node, but they don't seen
> to[/color]

Maybe, as so often, it's a namespace issue. XHTML uses a namespace. So
the XPath expressions must use the same namespace, too.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
  #4  
Old March 8th, 2006, 02:05 PM
Yoav Shapira
Guest
 
Posts: n/a
Default Re: XPath question: selecting content between two nodes

Thank you very much: this makes sense and I'll try it out.

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles