473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 6027
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--- <UNITS>Metric</UNITS> <UNITS>another</UNITS>...
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 2.6.16 and php 5.1.4. I tried a few variations,...
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 understand why i can't get the whole result. the result...
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 use php 4.x.x instead, Is there a way to install...
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> <price>822.51</price> </product> <product>...
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 database... It's fairly simple... Check...
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: $xml =...
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 search and read the xml files, I get this error: ...
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 different rss feeds in the past, and even stranger in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.