473,743 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
SimpleXMLElemen t 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 6057
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('te xt.xml');

return?
On 10 nov, 17:37, alexus <ale...@gmail.c omwrote:
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
SimpleXMLElemen t 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.c omwrote:
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
SimpleXMLElemen t 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
SimpleXMLElemen t 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...@gma il.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('te xt.xml');

return?

On 10 nov, 17:37, alexus <ale...@gmail.c omwrote:
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
SimpleXMLElemen t 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...@gma il.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.c omwrote:
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
SimpleXMLElemen t 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"
<alvaroNOSPAMTH A...@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
SimpleXMLElemen t 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:Envelop e xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema" xmlns:xsi="http ://
www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<searchRespon se xmlns="http://api.cj.com">
<out xmlns="http://api.cj.com">
<advertisers xmlns="http://advertiser.serv ice.cj.com">
<ns1:Advertiser Data xmlns:ns1="http ://vo.domain.cj.co m">
<cid xmlns="http://vo.domain.cj.co m">1656602</cid>
<clickCommissio n xmlns="http://vo.domain.cj.co m">0.0</
clickCommission >
<leadCommissi on xmlns="http://vo.domain.cj.co m"></
leadCommission>
<linkTypes xmlns="http://vo.domain.cj.co m">
<ns2:string xmlns:ns2="http ://api.cj.com">Ban ner</ns2:string>
<ns2:string xmlns:ns2="http ://api.cj.com">Tex t Link</
ns2:string>
<ns2:string xmlns:ns2="http ://api.cj.com">Key word Link</
ns2:string>
</linkTypes>
<name xmlns="http://vo.domain.cj.co m">Sony Style Canada</name>
<networkRank xmlns="http://vo.domain.cj.co m">3</networkRank>
<performanceInc entives xmlns="http://vo.domain.cj.co m">true
</performanceInce ntives>
<primaryCategor yId xmlns="http://vo.domain.cj.co m">397
</primaryCategory Id>
<primaryCategor yName xmlns="http://vo.domain.cj.co m">
<ns2:string xmlns:ns2="http ://api.cj.com">Con sumer Electronics
</ns2:string>
</primaryCategory Name>
<relationshipSt atus xmlns="http://vo.domain.cj.co m">joined
</relationshipSta tus>
<saleCommissi on xmlns="http://
vo.domain.cj.co m">3.5000000000 000004%</saleCommission> <sevenDayEPC
xmlns="http://vo.domain.cj.co m">10.551</sevenDayEPC><th reeMonthEPC
xmlns="http://vo.domain.cj.co m">9.325</threeMonthEPC></
ns1:AdvertiserD ata></advertisers><cu rrentPage xmlns="http://
advertiser.serv ice.cj.com">0</currentPage><re sultsPerpage
xmlns="http://advertiser.serv ice.cj.com">1</
resultsPerpage> <totalResults xmlns="http://
advertiser.serv ice.cj.com">48</totalResults></out></searchResponse> </
soap:Body></soap:Envelope>

Nov 10 '08 #7
alexus escribió:
>><?php
$xml=simplexm l_load_file ('test.xml');
print_r($xml) ;
?>
[...]
<soap:Envelop e xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema" xmlns:xsi="http ://
www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<searchRespon se 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));
?>

SimpleXMLElemen t Object
(
[Body] =SimpleXMLEleme nt Object
(
)

)

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

# SimpleXMLElemen t->registerXPathN amespace — Creates a prefix/ns context
for the next XPath query
# SimpleXMLElemen t->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
3708
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
14771
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, I found at http://us3.php.net/manual/en/function.simplexml-load-string.php $xml = simplexml_load_string($newsMLString, 'SimpleXMLElement',
1
4695
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 i get is only some part of the respective url (the one i tried to load). The following is my php code to open the file: $file=...
2
6495
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 simplexml_load_file function on php 4, if yes PLEASE let me know, else PLEASE suggest a function to parse xml files easily...... Thank u....
2
9827
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> <sku>10002</sku>
2
3230
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 it....///// // feed // // LOADS THE RSS FEED FOR // LOOPS THROUGH AND FORMATS/FILTERS POSTS // PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB // IF THERE ARE NEW POSTS, ADD THEM TO THE DATABASE ///// public function feed($feed,$type) { if...
7
10907
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 = simplexml_load_file("news_headlines_xml.php"); This is generating a parser error: It looks as if it's trying to parse the actual PHP script, and not the generated XML. I have set the MIME type on the PHP file to text/xml. Here is the script that generates the XML:
1
7206
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: When I open the resulting URLs in a browser, I can see the xml data just fine, and I have tried this on to different computers and servers, with the same result. Here is my code (minus the access keys for the databases):
4
11355
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 that if i put the feed source on our server as a .xml file then my code parses it successfully. The relevant code snippet: $xml = simplexml_load_file("http://www.quidco.com/blog/?feed=rss2",'SimpleXMLElement', LIBXML_NOCDATA); The errors i get...
0
8970
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8795
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9486
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9344
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8218
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6057
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4572
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.