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 8010713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:49:21+00:00 2026-06-04T18:49:21+00:00

I am importing some html into a dom document ans use xpath to extract

  • 0

I am importing some html into a dom document ans use xpath to extract the html part I am interested in. See below:

$dom = new DOMDocument();
@$dom->loadHTML(‘$myHtmlFileHere’);
$xpath_dom_doc = new DomXPath($dom);
$dom_object = $dom_document->query(‘myPathHere’);

Here below the html structure “returned”:

<div>GROUP A</div>
<span>aaa</span>
<span>zzz awesome</span>
<span>eee</span>

<div>GROUP B</div>
<span>fff</span>

<div>GROUP C</div>
<span>zzz</span>
<span>uuu</span>
<span>iii</span>
<span>rrr</span>

As you see I have categories (GROUP A, GROUP B and GROUP C). In the spans below each category I have information related to the category. What I would like is send to a db the span content with the related category. The problem that I am confronted to is that the div tag of the category is not wrapping the spans. So I do not see how I can manage that. hope someone can help. thank you in advance. Cheers. Marc

  • 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-06-04T18:49:22+00:00Added an answer on June 4, 2026 at 6:49 pm

    What about the following-sibling xpath function? You should be careful, though, and only select the siblings up to a next div.

    For example, tested with xsh2:

    $div = //div[2] ;
    ls $div/following-sibling::span[count(preceding-sibling::div)=1+count($div/preceding-sibling::div)] ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use loadData method to load some html content into a webview, but when
I'm importing some arbitrary HTML into a DOMDocument using the loadHTML() function, eg.: $html
I'm importing some images dynamically into a SWF from an external site using AS2.
I am learning ruby on rails. I started by importing some data into a
I'm building a browser extension that will insert a chunk of HTML into some
I am trying to incorporate some HTML into a silverlight application however even commercial
I'm importing some data from another test/bug tracking tool into tfs, and I would
I am injecting some html + css into every page from my firefox plugin.
I wrote a bit of html with some css styling injected into a third
I'm importing some XML to C#, and want to be able to access data

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.