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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:15:26+00:00 2026-05-23T05:15:26+00:00

I have an XML document from which I want to extract some data: <tnt:results>

  • 0

I have an XML document from which I want to extract some data:

<tnt:results>
<tnt:result>
<Document id="id1">
<impact _blabla_ for="tree.def" name="Something has changed"
select="moreblabla">true</impact>
<impact _blabla_ for="plant.def" name="Something else has changed"
select="moreblabla">true</impact>
</Document>
</tnt:result>
</tnt:results>

in reality there is no new line — it’s one continuous string and and there can be multiple < Document > elements. I want to have a regular expression that extracts:

  • id1
  • tree.def / plant.def
  • Something has changed / Something else has changed

I was able to come up with this code so far, but it only matches the first impact, rather than both of them:

preg_match_all('/<Document id="(.*)">(<impact.*for="(.*)".*name="(.*)".*<\/impact>)*<\/Document>/U', $response, $matches);

The other way to do it would be to match everything inside the Document element and pass it through a RegEx once more, but I thought I can do this with only one RegEx.

Thanks a lot in advance!

  • 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-23T05:15:27+00:00Added an answer on May 23, 2026 at 5:15 am

    Just use DOM, it’s easy enough:

    $dom = new DOMDocument;
    $dom->loadXML($xml_string);
    
    $documents = $dom->getElementsByTagName('Document');
    foreach ($documents as $document) {
        echo $document->getAttribute('id');     // id1    
    
        $impacts = $document->getElementsByTagName('impact');
        foreach ($impacts as $impact) {
            echo $impact->getAttribute('for');  // tree.def
            echo $impact->getAttribute('name'); // Something has changed
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file in which I want to extract data from certain
I have an XML document from which I want to remove white spaces and
I have a JSP which attaches a XSL to an XML document pulled from
I have one XML document which I want to store it inside ViewState so
I have created a PHP script which builds a table from an XML document
I have a XML document which contains around 4000 entries of data. The data
HI there, I have an xml that is dynamically generated, from which I want
I have an XML document that I want to generate unique IDs for. Some
I have a document which uses an XML namespace for which I want to
I have an XML document that I generate from an Entity Framework object. The

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.