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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:15:54+00:00 2026-06-14T11:15:54+00:00

I have a xml file with attributes XML Document <SET name=John lastname=Steve city=New York

  • 0

I have a xml file with attributes

XML Document

<SET name="John" lastname="Steve" city="New York" Country=""/>

This is converted to CSV file with 4 colums.

CSV File

Name,LastName,City,Country
John,Steve,New York,

I want to get the Empty content from Country and convert to a default text like USA

I will use str_replace to do this replacement.

The problem is that i don’t know how to get the Empty attribute, like if is empy var_dump.

Thanks

Conversion file.

$filexml = 'file.xml';
    if (file_exists($filexml)){
        $xml = simplexml_load_file($filexml);
$file = fopen('clients.csv', 'w');
        $header = array('Name', 'LastName', 'City', 'Country');
fputcsv($file, $header, ',', '"');
foreach ($xml->SET as $set){
$item = array();
            $value1 = $set->attributes()->name;
            $value2 = $set->attributes()->lastname;
            $value3 = $set->attributes()->city;
            $value4 = $set->attributes()->Country;

$search_country= array('','10','12')
$replace_country = array('USA','Argentina','Canada')
$item[] = $value1;
$item[] = $value2;
$item[] = $value3;
$item[] = str_replace($search_country, $replace_country, $value4);

fputcsv($file, $item, ',', '"');    
        }
        fclose($file);
    }
  • 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-14T11:15:56+00:00Added an answer on June 14, 2026 at 11:15 am

    Use empty to check if the values are empty

    $value4 = empty($set->attributes()->Country) ? "USA" : $set->attributes()->Country;
    
    • 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 formatted like this: <?xml version=1.0 encoding=utf-8?> <Snippets> <Snippet name=abc>
I have an XML file that I would like to map some attributes of
I'm using XmlWriterSettings to write Xml to file. I have elements with only attributes,
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have an xml document like this: <?xml version=1.0 encoding=UTF-8?> <foo:root xmlns:foo=http://abc.com# xmlns:bar=http://def.com xmlns:ex=http://ex.com>
I'm working with an XML document where a tag must either have one set
I have this XML document <AdditionalParameters> <PublishToPdf Type =System.Boolean>False</PublishToPdf> </AdditionalParameters> in my code and
I have a WIX XML document that contains 2,000+ file tags. I am trying
I have implemented a csv file builder that takes in an xml document applies

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.