Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Formatting XML results

Posted on 2007-03-30
8
Medium Priority
?
173 Views
Last Modified: 2010-05-18
I'm using a PHP and XML script to connect to a remote server and retrive data. I have most of it setup, but I'm trying to format the data that gets returned.

For example, if I use

var_dump($response);

to dump my results, I get something like the following:

object(DomainInfDataResponse)#15 (12) { ["name:private"]=>  string(14) "domainname.pl" ["status:private"]=>  string(6) "Active"  ["nss:private"]=>  array(2) { [0]=>  object(DomainNs)#20 (2) { ["name:private"]=>  string(15) "ns1.domainname.pl" ["ip:private"]=>  string(0) "" } [1]=>  object(DomainNs)#22 (2) { ["name:private"]=>  string(15) "ns2.domainname.pl" ["ip:private"]=>  string(0) "" } } ["holder:private"]=>  object(DomainHolder)#23 (4) { ["class:private"]=>  string(11) "Company" ["remark:private"]=>  string(21) "changed admin by name" } ["admins:private"]=>  array(1) { [0]=>  string(10) "NOC-453" } ["techs:private"]=>  array(1) { [0]=>  string(10) "NOC-453" } ["account:private"]=>  string(8) "00000161" ["regDate:private"]=>  string(10) "2001-06-27" ["renDate:private"]=>  string(10) "2007-06-27" ["result:private"]=>  object(Result)#6 (5) { ["code:private"]=>  string(4) "1000"  } ["type:protected"]=>  int(2) }

To retrive a single value from the response, I thought all I needed was:
$domain = $response=>name;

but that doesn't work.

How would I call a single variable?
0
Comment
Question by:thunder99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 4

Expert Comment

by:secondv
ID: 18823137
PHP5?

Could you provide some code, or give the output from:

print_r($response);
0
 

Author Comment

by:thunder99
ID: 18823363
Hi Secondv

Yes, it's php5.

print_r($response); gives:

DomainInfDataResponse Object ( [name:private] => domainname.pl [status:private] => Active [billingStatus:private] => Billable [nss:private] => Array ( [0] => DomainNs Object ( [name:private] => ns1.domainname.pl [ip:private] => ) [1] => DomainNs Object ( [name:private] => ns2.domainname.pl [ip:private] => ) ) [holder:private] => DomainHolder Object ( [class:private] => Company [remark:private] => changed admin by name ) [admins:private] => Array ( [0] => NOC-453 ) [techs:private] => Array ( [0] => NOC-453 ) [account:private] => 00000161 [regDate:private] => 2001-06-27 [renDate:private] => 2007-06-27 [result:private] => Result Object ( [code:private] => 1000 [msg:private] => Command completed successfully [value:private] => [reasonCode:private] => [reasonMsg:private] => ) [type:protected] => 2 )["type:protected"]=>  int(2) }

I can't really post the code as it's coming from lots of config files that are been called once.

The XML command that's been created looks like:

$command = new DomainInfoCommand("domainname.pl");
$response = CommandProcessor::process($command);
$result = $response->getResult();

//Test it//
var_dump($response);
print_r($response);

I actually had it working before, and then didn't save some changes and can't remember how I did it.


0
 
LVL 4

Accepted Solution

by:
secondv earned 1000 total points
ID: 18823570
To get a value:

echo $response->name;

However, if the variables are private "[name:private]" you won't be able to access it that way.

(Fatal error: Cannot access private property DomainInfDataResponse::$name in xxxx on line xx)

What you could do, is add a function inside the class that will return a given value.. such as:

public function get_value($var)
{
      return $this->$var;
}

$response->get_value('name');


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:wakemup
ID: 18824661
You can also use a generic __get($varname) function so:

function __get($varname) {

}
0
 
LVL 2

Expert Comment

by:wakemup
ID: 18824672
Sorry:

function __get($varname) {
  return $this->$varname;
}

This should work in php 5.0+
0
 
LVL 2

Assisted Solution

by:wakemup
wakemup earned 1000 total points
ID: 18824692

You can then just call '$this->Fred' and the __get function gets called automatically in the background and the value is returned without you having to do a get_fred, get_john function or a get($varname) and explicitly saying which variable you want. PHP 5 is cool like this.

There is also a __set($varname, $varvalue) which does the same the other way. Those are two underscores by the way.
0
 

Author Comment

by:thunder99
ID: 18825772
Can't get any of those methods to work. I'll go through some of the other files that are been called to see if it gives any hints as to what I need.
0
 

Author Comment

by:thunder99
ID: 19125851
Sorry for the delay in getting back to this question. Both of the solutions offered by secondv and wakemup work, so I'm splitting the points.

Again apoligies for leaving it open so long.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question