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

  • Home
  • SEARCH
  • 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 162569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:24:52+00:00 2026-05-11T11:24:52+00:00

I am trying to use xPath to traverse through the code of a newspaper

  • 0

I am trying to use xPath to traverse through the code of a newspaper (for the sake of practice) right now I’d like to get the main article, it’s picture and the small description I get of it. But I’m not that skilled in xPath so far and I can’t get to the small description.

withing this code:

<div class='margenesPortlet'>  <div class='fondoprincipal'> <div class='margenesPortlet'> <a href='notas/n1092329.htm' ><img id='LinkNotaA1_Foto' src='http://i.oem.com.mx/5cfaf266-bb93-436c-82bc-b60a78d21fb6.jpg' height='250' width='300' border='0' /></a>  <div class='piefoto_esto'>Un tubo de 12 pulgadas al lado de la Vialidad Sacramento que provoc&#243; el corte del servicio durante toda la ma&#241;ana y hasta alrededor de las cuatro de la tarde. Foto: El Heraldo de Chihuahua</div>  <div class='cabezaprincesto'><a href='notas/n1092329.htm' class='cabezaprincesto'  >Sin agua 8 mil usuarios</a></div> <div class='resumenesto'><a href='notas/n1092329.htm' class='resumenesto'  >La ruptura de una l&#237;nea en el tanque de rebombeo de agua Sacramento dej&#243; sin servicio a ocho mil usuarios, en once colonias del sur de la ciudad. </a></div> </div> </div>  </div> 

I’ve want to get the picture (with or without caption) and then the title of the article. These 3 things I can get by using:

//div[@class=’fondoprincipal’] <– gives me the main image and caption

//a[@class=’cabezaprincesto’]/text() <– gives me the article’s title

but I can’t get ahold of the small description which is the div with class=’resumenesto’, I haven’t tried getting anything by that id because the same id is used over and over through the rest of the HTML so it returns lots of extra items.

How can I get this particular one? and then would any of you recommend me a good way of parsing it to another webpage? I was thinking maybe php writing some html using those values but I’m not sure really…


Edit

What I mean by ‘this particular one’ is how do I get this div class=’resumenesto’, the one residing within div class=’fondoprincipal’…


Edit 2

Thank you, now xPath Traversing is a little bit more clear. But then about my second question, would any of you recommend me a good way of parsing it to another webpage? I was thinking maybe php writing some html using those values but I’m not sure really..

  • 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. 2026-05-11T11:24:52+00:00Added an answer on May 11, 2026 at 11:24 am

    You say ‘id’ of resumenesto, but in your code example the div you’re talking about has a class of resumenesto.

    Further, when you use an xpath of something like this:

    //div[@class='resumenesto'] 

    What you’re getting is a list of nodes matching that xpath. So if you want to specifically refer only to a single item in that list, you need to specify which item in the list:

    //div[@class='resumenesto'][1] 

    Further, what do you mean by ‘this particular one’? The only way to tell xpath specificity is to give it context, for instance ‘the div with class resumenesto that resides within some other div’, or ‘the first of the divs with class resumenesto’.

    Read W3Schools’ overview of XPath syntax for some more info.

    Edit:

    To get the div residing within ‘fondoprincipal’:

    //div[@class='fondoprincipal']//div[@class='resumenesto'] 

    This tells xpath to find any descendant div with class fondoprincipal within the document, and within that div, find any descendant div with class resumenesto.

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

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is a difference between a delegate and a datasource.… May 11, 2026 at 12:35 pm
  • added an answer <a href='#' onclick='return test();'>Test</a> <script type='text/javascript'> function test() { window.open('javascript:opener.write(window);',… May 11, 2026 at 12:35 pm
  • added an answer There's no guarantee that you won't get a collision between… May 11, 2026 at 12:35 pm

Related Questions

I am trying to use MinGW to compile a C program under Windows XP.
I am trying to use a stringstream object in VC++ (VStudio 2003) butI am
I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes
I am trying to use forms authentication with Active Directory but I need roles
I am trying to use Zend_Db_Select to write a select query that looks somewhat
I am struggling with a sensible logic loop for stripping out nodes from an
I am trying to get some xpath from xsl variable using xsl ver 1.0
I want to trim trailing whitespace at the end of all XHTML paragraphs. I
I am using TouchXml because of the given limitations of NSXML on the actual

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.