469,332 Members | 7,043 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

simplexml_load_file

i have test.xml file that i pull from someone, and when i try to load
it up into php

I get this

mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$

this is my code

<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>

yet when I open test.xml in firefox it looks all good

so my question what am I doing wrong? how can I load it into php and
be able to parse it? also is there a way to see error code to see xml
wasn't loaded properly
Nov 10 '08 #1
7 5787
take the space out from simplexml_load_file ('text.xml').... the
correct syntax is simplexml_load_file('test.xml');

if that is not the problem ... is the file local or remote? is the
file accesible to php?? what does

echo file_exists('text.xml');

return?
On 10 nov, 17:37, alexus <ale...@gmail.comwrote:
i have test.xml file that i pull from someone, and when i try to load
it up into php

I get this

mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$

this is my code

<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>

yet when I open test.xml in firefox it looks all good

so my question what am I doing wrong? how can I load it into php and
be able to parse it? also is there a way to see error code to see xml
wasn't loaded properly
Nov 10 '08 #2
Post the source code for the page explorer returns. Sometimes arrays
will not show up correctly on explorer and you must view source to see
if you are getting an array back.

Example. in explorer you might see..
blue red yellow

when php is saying:

array(

[1]->blue
[2]->red
[3]->yellow

)


On 10 nov, 17:37, alexus <ale...@gmail.comwrote:
i have test.xml file that i pull from someone, and when i try to load
it up into php

I get this

mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$

this is my code

<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>

yet when I open test.xml in firefox it looks all good

so my question what am I doing wrong? how can I load it into php and
be able to parse it? also is there a way to see error code to see xml
wasn't loaded properly
Nov 10 '08 #3
alexus escribió:
i have test.xml file that i pull from someone, and when i try to load
it up into php

I get this

mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$

this is my code

<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>
I my (short) experience with SimpleXML I've noticed that print_r() and
var_dump() don't always display the objects accurately. Try accessing
some piece of data. If you don't get any warning when calling
simplexml_load_file() I don't think there loading itself failed.

Also, feel free to post here a short version of your XML file so we can
have a look.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 10 '08 #4
On Nov 10, 12:26*pm, asismorodo <asismor...@gmail.comwrote:
take the space out from simplexml_load_file ('text.xml').... the
correct syntax is simplexml_load_file('test.xml');

if that is not the problem ... is the file local or remote? is the
file accesible to php?? *what does

echo file_exists('text.xml');

return?

On 10 nov, 17:37, alexus <ale...@gmail.comwrote:
i have test.xml file that i pull from someone, and when i try to load
it up into php
I get this
mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$
this is my code
<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>
yet when I open test.xml in firefox it looks all good
so my question what am I doing wrong? how can I load it into php and
be able to parse it? also is there a way to see error code to see xml
wasn't loaded properly

space is not a problem, and file is actually is local, if i use
different file (more simpler) it works

Nov 10 '08 #5
On Nov 10, 12:29*pm, asismorodo <asismor...@gmail.comwrote:
Post the source code for the page explorer returns. *Sometimes arrays
will not show up correctly on explorer and you must view source to see
if you are getting an array back.

Example. in explorer you might see..

blue red yellow

when php is *saying:

array(

[1]->blue
[2]->red
[3]->yellow

)

On 10 nov, 17:37, alexus <ale...@gmail.comwrote:
i have test.xml file that i pull from someone, and when i try to load
it up into php
I get this
mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$
this is my code
<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>
yet when I open test.xml in firefox it looks all good
so my question what am I doing wrong? how can I load it into php and
be able to parse it? also is there a way to see error code to see xml
wasn't loaded properly
i dont have an array, whatever i post it this is the actual code

Nov 10 '08 #6
On Nov 10, 12:47*pm, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
alexus escribió:
i have test.xml file that i pull from someone, and when i try to load
it up into php
I get this
mbp:cj alexus$ php api.php
SimpleXMLElement Object
(
)
mbp:cj alexus$
this is my code
<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>

I my (short) experience with SimpleXML I've noticed that print_r() and
var_dump() don't always display the objects accurately. Try accessing
some piece of data. If you don't get any warning when calling
simplexml_load_file() I don't think there loading itself failed.

Also, feel free to post here a short version of your XML file so we can
have a look.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<searchResponse xmlns="http://api.cj.com">
<out xmlns="http://api.cj.com">
<advertisers xmlns="http://advertiser.service.cj.com">
<ns1:AdvertiserData xmlns:ns1="http://vo.domain.cj.com">
<cid xmlns="http://vo.domain.cj.com">1656602</cid>
<clickCommission xmlns="http://vo.domain.cj.com">0.0</
clickCommission>
<leadCommission xmlns="http://vo.domain.cj.com"></
leadCommission>
<linkTypes xmlns="http://vo.domain.cj.com">
<ns2:string xmlns:ns2="http://api.cj.com">Banner</ns2:string>
<ns2:string xmlns:ns2="http://api.cj.com">Text Link</
ns2:string>
<ns2:string xmlns:ns2="http://api.cj.com">Keyword Link</
ns2:string>
</linkTypes>
<name xmlns="http://vo.domain.cj.com">Sony Style Canada</name>
<networkRank xmlns="http://vo.domain.cj.com">3</networkRank>
<performanceIncentives xmlns="http://vo.domain.cj.com">true
</performanceIncentives>
<primaryCategoryId xmlns="http://vo.domain.cj.com">397
</primaryCategoryId>
<primaryCategoryName xmlns="http://vo.domain.cj.com">
<ns2:string xmlns:ns2="http://api.cj.com">Consumer Electronics
</ns2:string>
</primaryCategoryName>
<relationshipStatus xmlns="http://vo.domain.cj.com">joined
</relationshipStatus>
<saleCommission xmlns="http://
vo.domain.cj.com">3.5000000000000004%</saleCommission><sevenDayEPC
xmlns="http://vo.domain.cj.com">10.551</sevenDayEPC><threeMonthEPC
xmlns="http://vo.domain.cj.com">9.325</threeMonthEPC></
ns1:AdvertiserData></advertisers><currentPage xmlns="http://
advertiser.service.cj.com">0</currentPage><resultsPerpage
xmlns="http://advertiser.service.cj.com">1</
resultsPerpage><totalResults xmlns="http://
advertiser.service.cj.com">48</totalResults></out></searchResponse></
soap:Body></soap:Envelope>

Nov 10 '08 #7
alexus escribió:
>><?php
$xml=simplexml_load_file ('test.xml');
print_r($xml);
?>
[...]
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<searchResponse xmlns="http://api.cj.com">
Right. The ":" in tags mean namespaces. Namespaces need a special
handling in SimpleXML. For instance:

<?php
$xml=simplexml_load_file ('test.xml');
print_r($xml->children('soap', TRUE));
?>

SimpleXMLElement Object
(
[Body] =SimpleXMLElement Object
(
)

)

You can also set a namespace context and run an Xpath query:

# SimpleXMLElement->registerXPathNamespace — Creates a prefix/ns context
for the next XPath query
# SimpleXMLElement->xpath — Runs XPath query on XML data

Alternatively, there's a SOAP extension in PHP (but I've never used it,
I can't tell you whether it suits your needs):

http://www.php.net/soap
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 11 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rainer Mohr | last post: by
2 posts views Thread by mandric | last post: by
1 post views Thread by kencana | last post: by
2 posts views Thread by Harsha | last post: by
7 posts views Thread by flydev | last post: by
4 posts views Thread by newzdog | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.