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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:07:09+00:00 2026-05-12T19:07:09+00:00

I am parsing a HTML document with XPATH and I want to keep all

  • 0

I am parsing a HTML document with XPATH and I want to keep all the inner html tags.

The html in question is a unordered list with many list elements.

<ul id="adPoint1"><li>Business</li><li>Contract</li></ul>

I am parsing the document using the following PHP code

$dom = new DOMDocument();
@$dom->loadHTML($output);
$this->xpath = new DOMXPath($dom);
$testDom = $this->xpath->evaluate("//ul[@id='adPoint1']");
$test = $testDom->item(0)->nodeValue;
echo htmlentities($test);

For some reason the output always has the html tags omitted from it. I assume that this is because XPATH was not intended to be used in this way, but is there anyway around this?

I would really like to continue using XPATH as I already use it for parsing other areas of the page (single a href elements) without a problem.

EDIT: I know that there is a better way to get the data by iterating through the child elements of the UL. There is a more complicated part of the page which I also want to parse (block of javascript), but I am trying to provide an easier to understand example.

The actual block of code that I want is

<script language="javascript">document.write(rot_decode('<u7>Pbagnpg Qrgnvyf</u7><qy vq="pbagnpgQrgnvyf"><qg>Cu:</qg><qq>(58) 0078 8455</qq></qy>'));</script>

It has the problem that it omits all the closing tags but keeps the opening tags. I’m guessing it’s because XPATH is trying to parse the inner elements rather than just treating it as a string.

If I try and select the script element with

$testDom = $this->xpath->evaluate("//div[@id='businessDetails']/script");
$test = $testDom->item(0)->nodeValue;
echo htmlentities($test);

my output will be, which you can see is missing all the closing tags.

document.write(rot_decode('<u7>Pbagnpg Qrgnvyf<qy vq="pbagnpgQrgnvyf"><qg>Cu:<qq>(58) 0078 8455'));
  • 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-12T19:07:09+00:00Added an answer on May 12, 2026 at 7:07 pm

    I decided XPATH wasn’t suited for what I wanted and am now using PHP Simple HTML DOM Parser which is much better suited to the task.

    It maintains internal html formatting just fine.

    foreach($this->simpleDom->find('script[language=javascript]') as $script) {
            echo htmlentities($script->innertext());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 247k
  • Answers 247k
  • 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
  • Editorial Team
    Editorial Team added an answer Just cast the result to an int like so: PS>… May 13, 2026 at 8:43 am
  • Editorial Team
    Editorial Team added an answer I believe it's best practice to declare a variable as… May 13, 2026 at 8:43 am
  • Editorial Team
    Editorial Team added an answer SDL is a cross-platform library that allows you to directly… May 13, 2026 at 8:42 am

Related Questions

I am currently scraping some data from the internet and converting into xml documents.
Trying to parse an HTML document and extract some elements (any links to text
I can't for the life of me understand why the following regex can't match
I have some document stored as a large String. In the String I have

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.