Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:36:20+00:00 2026-05-23T14:36:20+00:00

I’m using Opera 11.50 and I have a JavaScript-function that works as a callback

  • 0

I’m using Opera 11.50 and I have a JavaScript-function that works as a callback of an Ajax-request:

function nextPageCallback(responseText, responseXML) {
    if (responseXML && responseXML.documentElement) doc = responseXML.documentElement;
    else {
        doc = document.createElement("html");
        doc.innerHTML = responseText.replace(/[\n\r]/g, "").replace(/^.*\<html.*?\>|\<\/html.*$/i, "");
    }
    table = doc.getElementsByTagName("table")[1];

    if (table) {
        var trs;

        trs = document.evaluate("descendant::tr[count(td) > 1]", table, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

        for (var pos = 0; pos < trs.snapshotLength; pos++) {
            var tr = trs.snapshotItem(pos);
            var link;

            link = tr.innerHTML.match(/href=["'](\/path\/[^"']+?)["']/i)[1];
            linkX = document.evaluate("descendant::a[contains(@href, '/path/')]", tr, null, XPathResult.STRING_TYPE, null);
        }
    }
}

The main idea is to parse the table for certain links and then do something with the A– and TR-elements (further code is pointless for this issue and thus omitted).

The assignment to trs works, there are elements in the snapshot. The TRs will be moved around later so I need a snapshot.

The problem is with the last two lines. link is assigned by using plain old (error prone) RegEx and up to now works since there has been only one link that contains “/path/”. Now linkX should end up with the same value. If you wonder why there’s STRING_TYPE, well, nothing else works, not even ANY_TYPE (they all cause an XPathException: TYPE_ERR).

linkX is set to what seems to be the link text or innerText of the A-element. However, I want the href-attribute.

I already tried various things like using a namespace-resolver

function nsr() {
    return "http://www.w3.org/1999/xhtml";
}
:
            linkX = document.evaluate("descendant::a[contains(@href, '/path/')]", tr, nsr, XPathResult.STRING_TYPE, null);

but it isn’t even called.

I also added more stuff at the end of the XPath like /parent::node(), but nothing works.

Does it have something to do that I’m using a DOM-structure that was returned by document.evaluate()? Is my XPath wrong? How do I fix this?


EDIT: As requested, here’s a sample response that appears in responseText.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>Type</th>
          <th>Id</th>
          <th>Name</th>
          <th>Serialnumber</th>
        </tr>
      </thead>
      <tr>
        <td>Media</td>
        <td><a href="/path/2355">2355</a></td>
        <td>Sampler</td>
        <td>A65270-D32</td>
      </tr>
      <!-- more TRs of the structure above -->
      <tr>
        <td colspan="4" style="text-align:center;">
          <a href="/list/1">Previous</a>&nbsp;
          <a href="/list/3">Next</a>&nbsp;
        </td>
      </tr>
    </table>
  </body>
</html>

Regarding the code above it executes the else:

else {
    doc = document.createElement("html");
    doc.innerHTML = responseText.replace(/[\n\r]/g, "").replace(/^.*\<html.*?\>|\<\/html.*$/i, "");
}

What the code should do is find all TRs and in the TR the link containing “/path/”. For further processing I need the TR-element and the href-attribute of A.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:36:20+00:00Added an answer on May 23, 2026 at 2:36 pm

    What the code should do is find all
    TRs and in the TR the link containing
    “/path/”. For further processing I
    need the TR-element and the
    href-attribute of A.

    This XPath expression selects the wanted nodes:

     //x:tr[//x:a[contains(@href, '/path/')]]
    |
     //x:tr//x:a/@href[contains(.,'/path/')] 
    

    Here the prefix x must be associated to the (default) namespace "http://www.w3.org/1999/xhtml".

    Please, do note that XML and XPath are case-sensitive — in the provided XML document there are no element with upper-case names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.