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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:49:51+00:00 2026-06-07T16:49:51+00:00

I am trying to output a xml file to an array thats then outputted

  • 0

I am trying to output a xml file to an array thats then outputted to screen. The xml file loads I know it loads because as I can output entry > Id but I can not access its child nodes. I need the data located in.

content > s:organisationSummay
content > s:organisationSummay > s:address
content > s:organisationSummay > s:geographicCoordinates

how would I access the the data located in s:organisationSummay ,s:address, s:geographicCoordinates so I can getElementsByTagName for each items in that child node.

$doc2 = new DOMDocument();
$url  = 'http://v1.syndication.nhschoices.nhs.uk/organisations/'.$_POST['ServiceType'].'/postcode/'.$_POST['PostCode'].'.xml?apikey=??&range=50';
echo $url;

$doc2->load($url);
$arrFeeds = array();

foreach ($doc2->getElementsByTagName('entry') as $node) 
{
  echo $node->getElementsByTagName($content->'s:name');

  $itemRSS = array (
    'PracticeName' => $organisationSummary->getElementsByTagName('s:name')->item(0)->nodeValue
  );

  array_push($arrFeeds, $itemRSS);
}
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:s="http://syndication.nhschoices.nhs.uk/services" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">NHS Choices - GP Practices Near Postcode - ls1- Within 50km</title>
  <id>http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/postcode/bd164jt?range=50</id>
  <rights type="text">© Crown Copyright 2009</rights>
  <updated>2012-07-06T10:24:46+01:00</updated>
  <category term="Search"/>
  <logo>http://www.nhs.uk/nhscwebservices/documents/logo1.jpg</logo>
  <author>
    <name>NHS Choices</name>
    <uri>http://www.nhs.uk</uri>
    <email>webservices@nhschoices.nhs.uk</email>
  </author>
  <link rel="self" type="application/xml" title="NHS Choices - GP Practices Near Postcode - ;ls1 - Within 50km" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/postcode/ls1?apikey=??&amp;range=50"/>
  <link rel="first" type="application/xml" title="first" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/postcode/ls1?apikey=??&amp;range=50&amp;page=1"/>
  <link rel="next" type="application/xml" title="next" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/postcode/Ls1?apikey=??&amp;range=50&amp;page=2"/>
  <link rel="last" type="application/xml" title="last" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/postcode/LS1?apikey=??&amp;range=50&amp;page=10"/>
  <link rel="alternate" title="NHS Choices - Find and choose services - GP Practices" href="http://www.nhs.uk/ServiceDirectories/pages/ServiceSearch.aspx?ServiceType=GP"/>
  <s:SearchCoords>439300,411100</s:SearchCoords>
  <entry>
    <id>http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/1</id>
    <title type="text">Medical Practice</title>
    <updated>2012-07-06T09:24:46Z</updated>
    <link rel="self" title="Medical Practice" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/1?apikey=??"/>
    <link rel="alternate" title="Medical Practice" href="http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=1"/>
    <content type="application/xml">
      <s:organisationSummary>
        <s:name>Medical Practice</s:name>
        <s:address>
          <s:addressLine>Health Care Centre</s:addressLine>
          <s:addressLine>2</s:addressLine>
          <s:addressLine>Town</s:addressLine>
          <s:addressLine>Yorkshire</s:addressLine>
          <s:postcode>?</s:postcode>
        </s:address>
        <s:contact type="General">
          <s:telephone>5558383</s:telephone>
        </s:contact>
        <s:geographicCoordinates>
          <s:northing>438880</s:northing>
          <s:easting>411444</s:easting>
          <s:longitude>-1.82821202227791</s:longitude>
          <s:latitude>53.996218047559</s:latitude>
        </s:geographicCoordinates>
        <s:Distance>0.5</s:Distance>
      </s:organisationSummary>
    </content>
  </entry>
  <entry>
    <id>http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/2</id>
    <title type="text">Surgery</title>
    <updated>2012-07-06T09:24:46Z</updated>
    <link rel="self" title="Surgery" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/1?apikey=??"/>
    <link rel="alternate" title="Surgery" href="http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=2"/>
    <content type="application/xml">
      <s:organisationSummary>
        <s:name>Surgery</s:name>
        <s:address>
          <s:addressLine>Healthcare Centre</s:addressLine>
          <s:addressLine>Kings</s:addressLine>
          <s:addressLine>Town</s:addressLine>
          <s:postcode>?</s:postcode>
        </s:address>
        <s:contact type="General">
          <s:telephone>555555</s:telephone>
          <s:email>Email</s:email>
        </s:contact>
        <s:geographicCoordinates>
          <s:northing>78421</s:northing>
          <s:easting>484100</s:easting>
          <s:longitude>-1.828987402220691</s:longitude>
          <s:latitude>53.987218047559</s:latitude>
        </s:geographicCoordinates>
        <s:Distance>0.5</s:Distance>
      </s:organisationSummary>
    </content>
  </entry>


</feed>
  • 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-07T16:49:53+00:00Added an answer on June 7, 2026 at 4:49 pm

    This is a namespaced document, so you need to use the proper namespace methods, e.g. DOMDocument::getElementsByTagNameNS.

    In addition, there is so much wrong with your loop that I suspect you’re either not including all the code or you really misunderstand how DOMDocument works.

    $NS = array(
        's'    => "http://syndication.nhschoices.nhs.uk/services",
        'atom' => "http://www.w3.org/2005/Atom",
    );
    
    $entries = array();
    
    foreach ($doc2->getElementsByTagNameNS($NS['s'], 'organisationSummary') as $node) 
    {
        $entries[] = array(
            'name'    => trim($node->getElementsByTagNameNS($NS['s'], 'name')->item(0)->textContent),
            'address' => keyByElementName($node->getElementsByTagNameNS($NS['s'], 'address')->item(0)),
            'geographicCoordinates' => keyByElementName($node->getElementsByTagNameNS($NS['s'], 'geographicCoordinates')->item(0)),
        );
    }
    
    function keyByElementName(DOMNode $node)
    {
        $elem = array();
        foreach ($node->childNodes as $child) {
            if ($child->nodeType===XML_ELEMENT_NODE) {
                $elem[$child->localName] = trim($child->textContent);
            }
        }
        return $elem;
    }
    

    However, consider using DOMXPath or SimpleXML, as these will be easier than dom traversal.

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

Sidebar

Related Questions

I'm trying to validate an XML file, but I get the following error: Can
I am trying to output a XML file using Python and lxml However, I
I'm trying to output an xml file blog.xml as yaml, for dropping into vision.app,
I am trying to generate an output XML file from a master xml file
Trying to read into an object the following XML file (can be changed) into
I'm trying to output the data from an XML file datafeed, the support documents
I'm trying to output a xml file without xml head like I tried: Type
I'm parsing an XML file and trying to return the output to a div.
I am trying to output the text from xml through an html file.Xml file
I have small problem. I'm trying to work on an XML file, but 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.