1

In my index.html there's a div that will be filled with some html content returned from an ajax request to another web page. I need to highlight some specific part of the loaded html content that is determined by xpath. Using the code in the solution found here it's returning a null node. Obviously when i try to use an xpath that is referred to the code from the ajax request as shown:

var node = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

it returns a null node.

I'm searching for something useful for replace "document" inside the function with the purpose of obtain a not null node referred to the code from ajax and not from the index.html that still contains the empty div.

The div i need to fill is this: 'div id="mainAreaContent" /div' and here you can find what i want to insert (https://ideone.com/bseVSF), the path i'm using is /table/tr/td/table[1]/tr/td[2]/h3[2]/text(). The document variable is the index.html that calls the js script.

Community
  • 1
  • 1
Poggio
  • 131
  • 3
  • 9

1 Answers1

0

You wrote:

/table/tr/td/table[1]/tr/td[2]/h3[2]/text().

If I open your file in oXygen (an XML editor with XPath/XSLT etc support), and I make it valid (your referenced file is incomplete/broken), then your given XPath selects the text node "The Architecture and Datasets of Docear's Research Paper Recommender System" (sic).

You wrote:

The div i need to fill is this: 'div id="mainAreaContent" /div

I don't see any div in your XPath, nor anything with an id mainAreaContent in your source HTML, so if you are searching for that, it is correct that you get null: it isn't there.

About your XPath expression

The XPath you showed starts at the root. If your root is not <table>, but <html> for instance, you should change it to include the path up to your table element. The (incomplete) document you showed started at <table>, but I assume it is part of an HTML page. Perhaps your select expression should start like /html/body/div/p/table..., but I don't know, your didn't show that part.

Abel
  • 56,041
  • 24
  • 146
  • 247