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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:21:04+00:00 2026-05-26T18:21:04+00:00

I have many xml file’s, I do not want to get the value, but

  • 0

I have many xml file’s, I do not want to get the value, but check if they have a child child nod or no. so I use count instead of foreach. but my code always echo no if there have no $xml->book->date in the first $xml->book roop.

$xml = simplexml_load_file('some.xml');
if (@count($xml->book->date)>0){
    echo 'yes';
}else{
    echo 'no';
}

the xml tree like this

<?xml version="1.0" encoding="utf-8"?>
<Catalog>
    <book>
     <title/><description/><price/>
  </book>
  <book>
     <title/><description/><price/>
     <date/>  //(optional, there may be 0 to n [book] elements having a [date] element in the document)
  </book>
  <book>
     <title/><description/><price/>
  </book>
  <book>
     <title/><description/><price/>
     <date/>
  </book>
</Catalog>

For this document the result of the working version of “count($xml->book->date)” should be 2, i.e. > 0

EDIT: maybe do not use count, but how to check if have or not have date childnod in the whole xml file? Thanks.

  • 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-26T18:21:05+00:00Added an answer on May 26, 2026 at 6:21 pm

    If you want to check in the entire xml document, then I think you’ll have to loop through all the book elements-

    $found = false;
    foreach($xml->book as $book)
    {
        if(count($book->date)>0)
        {
            $found = true;
            break;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many XML-s and I downloaded using file or file_get_content, but the server
I have a large XML file (many MBs) that I cannot afford to download
I have an XML file which has many section like the one below: <Operations>
I have looked at many examples for validating an XML file against a DTD,
I have many xml files in my project. I want to find out R.id.details
I have application with internet access and don't want to store many string.xml files
I have seen in many XML file has the data inside this <![CDATA[ ]]>
I have created a custom xml file which I use as a config for
I want to parse some large XML file using linq to XML but I
I wanted to put my log4j.xml file in WEB-INF/conf directory where I have many

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.