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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:46:34+00:00 2026-05-30T01:46:34+00:00

For personal use I am currently writing a recursive PHP function that should process

  • 0

For personal use I am currently writing a recursive PHP function that should process a big amount of relatively big XML files. As I only need the value of 2-3 nodes I searched for a way to make this as memory- and traffic-saving as possible. So I’ve stumbled upon the PHP Object XMLReader, which doesn’t quite work as expected and isn’t really documented that well on PHP.net.
My current code is the following:

<?php
    $reader = new XMLReader();
    $reader->open('http://path.to.xml/file', 'UTF-8');
    $att1 = $reader->getAttribute('att1');
    $att2 = $reader->getAttribute('att2');
    $reader->close();
    echo var_dump($att1) . ' ' . var_dump($att2);
?>

As you can see this is pure debug, but it just echoes out NULL two times, which, according to the docs, is the case “if no attribute with the given name [are] found or […] positioned on an element node.”

The XML structure (actual file is bigger than 500 lines, but also contains CDATA tags sometimes):

<parentnode>
    <att1><![CDATA[ VAL1 ]]></att1>
    <randomtags>randomval</randomtags>
    <att2>VAL2</att2>
    <foo>bar</foo>
</parentnode>

I have almost no experience with XML and previously only used SimpleXML – once. I don’t want to parse the whole file, just these two values.

What I already tried:

  • encapsing the getAttribute parameter in < and >
  • statically calling the getAttribute Methods
  • changing the getAttribute parameter to include the parent node in multiple ways

Any tips or hints are welcome. 🙂

  • 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-30T01:46:35+00:00Added an answer on May 30, 2026 at 1:46 am

    You’re using

    $att1 = $reader->getAttribute('att1'); 
    

    but in your XML definition, att1 and att2 are elements, not attributes

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

Sidebar

Related Questions

I'm writing an application for personal use that will track how often I reach
I'm trying to find a source control for my own personal use that's as
I'm developing (another) java web framework for personal use, and in addition to that
I have a Perl script I wrote for my own personal use that fetches
Using PHP ... This is for my personal use so I'm thinking maybe 3-4
I'm currently writing some general purpose .net libraries that contain usual helper classes. For
I am currently working on an application in WPF/C# for personal use. I am
I am writing a small program for my personal use to practice learning C++
I currently use Visual Studio 2005 for all my personal projects, which means I'm
I'm currently in the process of converting some small personal web sites from WebForms

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.