472,353 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 5938
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rainer Mohr | last post by:
Hi, I´m having some problems with simplexml_load_file() and cant find any sollution anywhere. Say, we have the following file: ---file.xml---...
2
by: mandric | last post by:
Hello, Can someone please enlighten me on how to preserve the <!]> element when parsing an xml file or string with simplexml. I'm using libxml...
1
by: kencana | last post by:
Hi all, I was wondering why I always get "failed to open stream: HTTP request failed!" error in either loading a normal or xml file. i don't...
2
by: Harsha | last post by:
Hi All, I am using simplexml_load_file function to parse xml files on my localhost. But the server hosting my domain has php 4.x.x. so i want to...
2
by: doc1355 | last post by:
I have a XML file that looks like this: <?xml version="1.0" encoding="UTF-8"?> <products> <product> <sku>10001</sku> <qty>3</qty> ...
2
jamwil
by: jamwil | last post by:
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a...
7
by: flydev | last post by:
Hi, I am having issues using simplexml. I have generated an XML file using PHP (link), and I am trying to load it into a simplexml object using: ...
1
by: SnakesRule | last post by:
I'm trying to pull data from remote xml files to load the database of a library. My sources are www.amazon.com and www.ISBNdb.com. But when I try to...
4
by: newzdog | last post by:
Hi, I have a problem parsing an rss feed using simplexml_load_file - this is strange as i have used the same code to parse literally 1000s of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.