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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:31:09+00:00 2026-06-09T08:31:09+00:00

I have the following XML output from an API <?xml version=’1.0′ encoding=’UTF-8′?> <Response> <ReturnRow

  • 0

I have the following XML output from an API

<?xml version='1.0' encoding='UTF-8'?>
<Response>
    <ReturnRow Output1="11" Output2="12" Output3="13" Output4="14" Output5="15" />
    <ReturnRow Output1="21" Output2="22" Output3="23" Output4="24" Output5="25" />
    <Messages>
        <Message Code="INFO" Msg="Your request is successful." Type="APP"/>
    </Messages>       
</Response>

I’m trying to parse the above xml using PHP, loop the child element ReturnRown and echo out the Output1, Output2 into an HTML table.

Here’s my code currently:

$doc = new DOMDocument();
$doc->loadXML($test); //$test is holding the above XML
$node = $doc->getElementsByTagName( "ReturnRow" );
foreach ($node as $book) {
     var_dump($book);
}

But the above is not actually giving me the values of the Ouput1, Output2 etc.

What am I missing or doing wrong?

The result of my above PHP code:

object(DOMElement)#3 (18) { ["tagName"]=> string(9) "ReturnRow" ["schemaTypeInfo"]=> NULL        ["nodeName"]=> string(9) "ReturnRow" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1)     ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(9) "ReturnRow" ["baseURI"]=> string(20) "file:///W:/ischools/" ["textContent"]=> string(0) "" } object(DOMElement)#5 (18) { ["tagName"]=> string(9) "ReturnRow" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(9) "ReturnRow" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(9) "ReturnRow" ["baseURI"]=> string(20) "file:///W:/ischools/" ["textContent"]=> string(0) "" }
  • 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-09T08:31:10+00:00Added an answer on June 9, 2026 at 8:31 am

    In your case, i would prefer to use simplexml because it could return all attributes of a node in an easily iterable format, and use xpath to find the nodes you are interested in:

    $xml = '<'.'?xml version="1.0" encoding="UTF-8"?>
    <Response>
        <ReturnRow Output1="11" Output2="12" Output3="13" Output4="14" Output5="15" />
        <ReturnRow Output1="21" Output2="22" Output3="23" Output4="24" Output5="25" />
        <Messages>
            <Message Code="INFO" Msg="Your request is successful." Type="APP"/>
        </Messages>
    </Response>
    ';
    
    $doc = simplexml_load_string($xml);
    $node = $doc->xpath('//ReturnRow');
    foreach ($node as $book) {
        foreach ($book->attributes() as $name => $value) {
            var_dump((string)$name, (string)$value);
        }
    }
    

    If your input has always have these attributes you can use DOMNode’s getAttribute() method in your original code’s loop to get to the values:

    foreach ($node as $book) {
        var_dump($book->getAttribute('Output1'), $book->getAttribute('Output2'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8"?> <ExportData> <TransportHeader> <Timestamp>2011-01-16 06:00:33</Timestamp>
Hi I have the following xml <?xml version=1.0 encoding=UTF-8?> <root> <item> <name>john</name> <year>2010</year> </item>
I have following itemrenderer <?xml version=1.0 encoding=utf-8?> <s:MXAdvancedDataGridItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx focusEnabled=true> <s:Label id=lblData
I'm trying to deserialize the following XML output: <?xml version=1.0 encoding=ISO-8859-1?> <Foo> <Val>Data1</Val> </Foo>
I have the following output (via link) which displays the var_dump of some XML
I have following xml as a response to a service not i want to
I have some output from 3rd party software: Sample XML from the software: <testsuite
I have the following XML generated from various tables in my SQL SERVER database
We have a requirement to fetch information from the following API http://www.viralheat.com/developer/sentiment_api#method1 which can
Hi I have following XAML code which is the output from XamlWriter.Save(): <StackPanel Name=itemStack

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.