Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread ma...@behnke.biz
 There is another nice way.
You can pass a second value to the simple xml constructor which is a class
name to be used instead of SimpleXMLElement.
You can write your own class that extends SimpleXMLElement and override the
magic methods to skip the casting


Simon Schick simonsimc...@googlemail.com hat am 22. Februar 2012 um 00:16
geschrieben:

 Hi, Jay

 If you're not using the variable *$xmlCompany* somewhere else I'd try to
 skip the array and just do it with this single line:
 *$arrayLead[0]-Company = (string)
 $xml-SignonRq-SignonTransport-CustId-SPName;*

 The result should not differ from what you have now.

 Bye
 Simon

 2012/2/21 Jay Blanchard jay.blanch...@sigmaphinothing.org

  Howdy,
 
  My PHP chops are a little rough around the edges so I know that I am
  missing something. I am working with SimpleXML to retrieve values from
an
  XML file like this -
 
  $xmlCompany = $xml-SignonRq-SignonTransport-CustId-SPName;
 
  If I echo $xmlCompany I get the proper information.
 
  If I use $xmlCompany as an array value though, I get this object -
 
  $arrayLead[0]-Company = $xmlCompany; // what I did
  [Company] = SimpleXMLElement Object // what I got
 (
 [0] = Dadgummit
 )
  I tried casting AND THEN AS I TYPED THIS I figured it out...
 
  $xmlCompany = array((string)
  $xml-SignonRq-SignonTransport-CustId-SPName); // becomes an array
  $arrayLead[0]-Company = $xmlCompany[0]; // gets the right bit of the
array
 
  and the result is
 
   [Company] = Dadgummit
  Thanks for bearing with me!
 
 
 
 
 
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Jay Blanchard

On 2/22/2012 8:32 AM, ma...@behnke.biz wrote:

  There is another nice way.
You can pass a second value to the simple xml constructor which is a class
name to be used instead of SimpleXMLElement.
You can write your own class that extends SimpleXMLElement and override the
magic methods to skip the casting

I don't really see a need to add an extra layer or class extension when 
casting works fine. Am I wrong? Why add several lines of code in an 
extension class?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Marco Behnke
Am 22.02.12 16:04, schrieb Jay Blanchard:
 On 2/22/2012 8:32 AM, ma...@behnke.biz wrote:
   There is another nice way.
 You can pass a second value to the simple xml constructor which is a
 class
 name to be used instead of SimpleXMLElement.
 You can write your own class that extends SimpleXMLElement and
 override the
 magic methods to skip the casting

 I don't really see a need to add an extra layer or class extension
 when casting works fine. Am I wrong? Why add several lines of code in
 an extension class?

To keep the code readable?

$value = $xml-node;

vs.

$value = (String)$xml-node;

I like the first one. Plus you handle it to dynamically to the right type

function __get($value)
{
if is float return float casted value
if is boolean ...
and so on
}

-- 
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz




signature.asc
Description: OpenPGP digital signature


Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Jay Blanchard
 I don't really see a need to add an extra layer or class extension
 when casting works fine. Am I wrong? Why add several lines of code in
 an extension class?
 
 To keep the code readable?
 
 $value = $xml-node;
 
 vs.
 
 $value = (String)$xml-node;
 
 I like the first one. Plus you handle it to dynamically to the right type
 
 function __get($value)
 {
if is float return float casted value
if is boolean ...
and so on
 }

The code is no less readable my way, YMMV

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-21 Thread Simon Schick
Hi, Jay

If you're not using the variable *$xmlCompany* somewhere else I'd try to
skip the array and just do it with this single line:
*$arrayLead[0]-Company = (string)
$xml-SignonRq-SignonTransport-CustId-SPName;*

The result should not differ from what you have now.

Bye
Simon

2012/2/21 Jay Blanchard jay.blanch...@sigmaphinothing.org

 Howdy,

 My PHP chops are a little rough around the edges so I know that I am
 missing something. I am working with SimpleXML to retrieve values from an
 XML file like this -

 $xmlCompany = $xml-SignonRq-SignonTransport-CustId-SPName;

 If I echo $xmlCompany I get the proper information.

 If I use $xmlCompany as an array value though, I get this object -

 $arrayLead[0]-Company = $xmlCompany; // what I did
 [Company] = SimpleXMLElement Object // what I got
(
[0] = Dadgummit
)
 I tried casting AND THEN AS I TYPED THIS I figured it out...

 $xmlCompany = array((string)
 $xml-SignonRq-SignonTransport-CustId-SPName); // becomes an array
 $arrayLead[0]-Company = $xmlCompany[0]; // gets the right bit of the array

 and the result is

  [Company] = Dadgummit
 Thanks for bearing with me!







[PHP] SimpleXML and the Single String (SOLVED)

2012-02-20 Thread Jay Blanchard
Howdy,

My PHP chops are a little rough around the edges so I know that I am missing 
something. I am working with SimpleXML to retrieve values from an XML file like 
this - 

$xmlCompany = $xml-SignonRq-SignonTransport-CustId-SPName;

If I echo $xmlCompany I get the proper information.

If I use $xmlCompany as an array value though, I get this object - 

$arrayLead[0]-Company = $xmlCompany; // what I did
[Company] = SimpleXMLElement Object // what I got
(
[0] = Dadgummit
)
I tried casting AND THEN AS I TYPED THIS I figured it out...

$xmlCompany = array((string) $xml-SignonRq-SignonTransport-CustId-SPName); 
// becomes an array
$arrayLead[0]-Company = $xmlCompany[0]; // gets the right bit of the array

and the result is

 [Company] = Dadgummit
Thanks for bearing with me!






[PHP] SimpleXML - parsing attributes with a namespace

2011-06-03 Thread Anthony Gladdish
Hi,

Using following code does not parse the xml:id attribute. If I change the 
attribute's namespace to anything other than xml ( e.g. new:id ) then it 
works.

$string = XML
TEI xml:id=decten1tlsg01
teiHeader 
profileDesc 
particDesc
 person xml:id=interviewerTlsg01 /person
 /particDesc
 /profileDesc 
 /teiHeader 
/TEI
XML;
$xml = simplexml_load_string($string);
foreach($xml-teiHeader-profileDesc-particDesc-person[0]-attributes() as $a 
= $b) {
echo p$a = $b \n/p;
}

Is this a bug? And how do I get this to work?

Many thanks,
Anthony

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML - parsing attributes with a namespace

2011-06-03 Thread Anthony Gladdish
Hi,

Using following code does not parse the xml:id attribute. If I change the 
attribute's namespace to anything other than xml ( e.g. new:id ) then it 
works.

$string = XML
TEI xml:id=decten1tlsg01
teiHeader 
profileDesc 
particDesc
 person xml:id=interviewerTlsg01 /person
 /particDesc
 /profileDesc 
 /teiHeader 
/TEI
XML;
$xml = simplexml_load_string($string);
foreach($xml-teiHeader-profileDesc-particDesc-person[0]-attributes() as $a 
= $b) {
echo p$a = $b \n/p;
}

Is this a bug? And how do I get this to work?

Many thanks,
Anthony

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML/array duality (like particles waves)

2010-09-28 Thread Brian Dunning
I am kind of jacked here. I have a SimpleXML object that's been converted to an 
array. In one of the nodes, for no reason I can see, the array is populated 
differently if there is only one order_item than if there are multiple 
order_items.

If there is just one, my $order_item array looks like this:
Array
(
[order_item_product_code] = 1300
[order_item_description] = 4x8 photo cards (set of 20)
)

But if there are multiple items, I get this:
Array
(
[0] = SimpleXMLElement Object
(
[order_item_product_code] = 1060
[order_item_description] = 4x5.3 trueDigital print(s)
)

[1] = SimpleXMLElement Object
(
[order_item_product_code] = 1300
[order_item_description] = 4x8 photo cards (set of 20)
)
)

See my problem? I can't foreach through those and process the items in the same 
way.

In case it matters, here is that snip of what the original XML looks like, it's 
all good:
?xml version=1.0 encoding=UTF-8?
order xmlns=http://.com/; version=1.0
  order_items
order_item
  order_item_product_code finish=glossy1060/order_item_product_code
  order_item_description4x5.3 trueDigital 
print(s)/order_item_description
/order_item
order_item
  order_item_product_code finish=glossy1300/order_item_product_code
  order_item_description4x8 photo cards (set of 
20)/order_item_description
/order_item
  /order_items
/order

And here is the function I'm using to convert the XML to an array:
function xmlToArray($xml, $isChild = false) {
if($xml instanceof SimpleXMLElement) {
$xmlObject = $xml;
} elseif($isChild) {
return $xml;
} else {
try {
$xmlObject = new SimpleXMLElement($xml);
} catch(Exception $e) {
$string = $e-getMessage();
throw new Exception('Invalid XML found in ' . 
__FUNCTION__ . ' function on line '.__LINE__.'.');
}
}
$children = (array)$xmlObject-children();
if(is_array($children)) {
if(count($children) == 0) {
$children = '';
} else {
foreach($children as $element = $value) {
$children[$element] = xmlToArray($value, true);
}
}
}
return $children;
}

Any suggestions?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML/array duality (like particles waves)

2010-09-28 Thread Nathan Nobbe
On Tue, Sep 28, 2010 at 4:29 PM, Brian Dunning br...@briandunning.comwrote:

 I am kind of jacked here. I have a SimpleXML object that's been converted
 to an array.


how was the SimpleXMLElement converted to an array?

-nathan


Re: [PHP] SimpleXML/array duality (like particles waves)

2010-09-28 Thread Brian Dunning
If you read down to the bottom of the post, the function I used is given.


On Sep 28, 2010, at 3:47 PM, Nathan Nobbe wrote:

 On Tue, Sep 28, 2010 at 4:29 PM, Brian Dunning br...@briandunning.com wrote:
 I am kind of jacked here. I have a SimpleXML object that's been converted to 
 an array.
 
 how was the SimpleXMLElement converted to an array?
 
 -nathan 



Re: [PHP] SimpleXML/array duality (like particles waves)

2010-09-28 Thread Nathan Nobbe
On Tue, Sep 28, 2010 at 5:06 PM, Brian Dunning br...@briandunning.comwrote:

 If you read down to the bottom of the post, the function I used is given.


My apologies for the hasty response.  well, if i had to guess, id say thats
where the problem is.  why cant you just iterate over the object w/ the
built in functionality, which is to say, why bother converting to an array
in the first place?

-nathan


[PHP] simpleXML - can't add children - why? - stuck

2010-08-04 Thread MEM
Hello all,

I'm struggling here, but no joy so far.

Having this XML file that I'm loading using simplexml_load_file():
http://pastebin.com/JiW3LxWM

I need to add some domain:create children nodes after line 8.

What do I need to add?
This:
http://pastebin.com/mT27g3ZN

In order to do so, I have used the following php snipped:
http://pastebin.com/a1gG8tXx

I'm getting this warning and, after it, a fatal error:
Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]:
Cannot add child. Parent is not a permanent member of the XML tree.
(line number 1 of last paste bin)

Fatal error: Call to a member function addChild() on a non-object
(line number 2 of last paste bin)

Note that:
The constant used is correct. The php version is higher then 5.1.
On the same command, later on this code, I was able to create child
nodes with no issues.

I'm far (veery far) from being a guru, so please, what can I do to
debug this, and find out what's going on?


Thanks a lot,
Márcio

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML - Solved

2010-05-10 Thread Brian Dunning
I was able to resolve this by changing the XML file encoding from UTF-8 to 
ISO-8859-1. Works like a charm now, with the XML-encoded characters.

Thanks to all who offered their help.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-08 Thread Deva
I think that  should be amp; because you cant use  in xml as
independent alphbet

On 5/7/10, Dan Joseph dmjos...@gmail.com wrote:
 On Thu, May 6, 2010 at 8:02 PM, Brian Dunning br...@briandunning.comwrote:

 Hey all -

 I'm using simplexml-load-string just to validation a string of XML, and
 libxml-get-errors to return any errors. It's always worked before, but
 today
 it's choking on this line in the XML:

 client_orderitem_numberBasketball Personalized Notebook -
 Jeffapos;s/client_orderitem_number

 It's returning Premature end of data in tag client_orderitem_number line
 90 but as far as I can tell, Jeffapos;s is properly XML encoded. I can't
 debug this. Any suggestions?

 I have run the XML through a couple of online validators and it does come
 back as valid with no errors found. http://www.php.net/unsub.php


 I had this problem  It turned out to be some special characters in the
 tags or data that I had to strip out first, then load it thru the simplexml
 parser.  I will have to check my code when I get back to the office in the
 AM and I'll let you know what it was if you haven't figured it out by then.
 But that might get you started in fixing it.

 --
 -Dan Joseph

 www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
 Code NEWTHINGS for 10% off initial order

 http://www.facebook.com/canishosting
 http://www.facebook.com/originalpoetry


-- 
Sent from my mobile device

Devendra Jadhav
देवेंद्र जाधव

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-08 Thread Deva
 -  amp; added space because browser is converting it to  :)

On 5/8/10, Deva devendra...@gmail.com wrote:
 I think that  should be amp; because you cant use  in xml as
 independent alphbet

 On 5/7/10, Dan Joseph dmjos...@gmail.com wrote:
 On Thu, May 6, 2010 at 8:02 PM, Brian Dunning
 br...@briandunning.comwrote:

 Hey all -

 I'm using simplexml-load-string just to validation a string of XML, and
 libxml-get-errors to return any errors. It's always worked before, but
 today
 it's choking on this line in the XML:

 client_orderitem_numberBasketball Personalized Notebook -
 Jeffapos;s/client_orderitem_number

 It's returning Premature end of data in tag client_orderitem_number
 line
 90 but as far as I can tell, Jeffapos;s is properly XML encoded. I
 can't
 debug this. Any suggestions?

 I have run the XML through a couple of online validators and it does
 come
 back as valid with no errors found. http://www.php.net/unsub.php


 I had this problem  It turned out to be some special characters in
 the
 tags or data that I had to strip out first, then load it thru the
 simplexml
 parser.  I will have to check my code when I get back to the office in
 the
 AM and I'll let you know what it was if you haven't figured it out by
 then.
 But that might get you started in fixing it.

 --
 -Dan Joseph

 www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.
 Promo
 Code NEWTHINGS for 10% off initial order

 http://www.facebook.com/canishosting
 http://www.facebook.com/originalpoetry


 --
 Sent from my mobile device

 Devendra Jadhav
 देवेंद्र जाधव


-- 
Sent from my mobile device

Devendra Jadhav
देवेंद्र जाधव

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-08 Thread Peter Lind
On 8 May 2010 00:39, Nathan Nobbe quickshif...@gmail.com wrote:

 hmm, both the strings seem to work fine on my laptop:


+1. Have no problem with either string


-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-07 Thread Brian Dunning
This time simplexml-load-string also gave me the same error on the following 
line:

first_nameCharlie amp; Brady/first_name

Can anyone confirm whether simplexml-load-string will or will not accept or 
allow XML-encoded characters? It seems that it should and would be pretty 
surprising if it wouldn't.



On May 6, 2010, at 5:02 PM, Brian Dunning wrote:

 Hey all -
 
 I'm using simplexml-load-string just to validation a string of XML, and 
 libxml-get-errors to return any errors. It's always worked before, but today 
 it's choking on this line in the XML:
 
 client_orderitem_numberBasketball Personalized Notebook - 
 Jeffapos;s/client_orderitem_number
 
 It's returning Premature end of data in tag client_orderitem_number line 90 
 but as far as I can tell, Jeffapos;s is properly XML encoded. I can't debug 
 this. Any suggestions?
 
 I have run the XML through a couple of online validators and it does come 
 back as valid with no errors found.
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-07 Thread Nathan Nobbe
On Fri, May 7, 2010 at 4:32 PM, Brian Dunning br...@briandunning.comwrote:

 This time simplexml-load-string also gave me the same error on the
 following line:

 first_nameCharlie amp; Brady/first_name

 Can anyone confirm whether simplexml-load-string will or will not accept or
 allow XML-encoded characters? It seems that it should and would be pretty
 surprising if it wouldn't.


hmm, both the strings seem to work fine on my laptop:

php  var_dump(simplexml_load_string('first_nameCharlie amp;
Brady/first_name'));
object(SimpleXMLElement)#1 (1) {
  [0]=
  string(15) Charlie  Brady
}
php  var_dump(simplexml_load_string('client_orderitem_numberBasketball
Personalized Notebook - Jeffapos;s/client_orderitem_number'));
object(SimpleXMLElement)#1 (1) {
  [0]=
  string(41) Basketball Personalized Notebook - Jeff's
}


-nathan


[PHP] simplexml choking on apparently valid XML

2010-05-06 Thread Brian Dunning
Hey all -

I'm using simplexml-load-string just to validation a string of XML, and 
libxml-get-errors to return any errors. It's always worked before, but today 
it's choking on this line in the XML:

client_orderitem_numberBasketball Personalized Notebook - 
Jeffapos;s/client_orderitem_number

It's returning Premature end of data in tag client_orderitem_number line 90 
but as far as I can tell, Jeffapos;s is properly XML encoded. I can't debug 
this. Any suggestions?

I have run the XML through a couple of online validators and it does come back 
as valid with no errors found.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml choking on apparently valid XML

2010-05-06 Thread Dan Joseph
On Thu, May 6, 2010 at 8:02 PM, Brian Dunning br...@briandunning.comwrote:

 Hey all -

 I'm using simplexml-load-string just to validation a string of XML, and
 libxml-get-errors to return any errors. It's always worked before, but today
 it's choking on this line in the XML:

 client_orderitem_numberBasketball Personalized Notebook -
 Jeffapos;s/client_orderitem_number

 It's returning Premature end of data in tag client_orderitem_number line
 90 but as far as I can tell, Jeffapos;s is properly XML encoded. I can't
 debug this. Any suggestions?

 I have run the XML through a couple of online validators and it does come
 back as valid with no errors found. http://www.php.net/unsub.php


I had this problem  It turned out to be some special characters in the
tags or data that I had to strip out first, then load it thru the simplexml
parser.  I will have to check my code when I get back to the office in the
AM and I'll let you know what it was if you haven't figured it out by then.
But that might get you started in fixing it.

-- 
-Dan Joseph

www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
Code NEWTHINGS for 10% off initial order

http://www.facebook.com/canishosting
http://www.facebook.com/originalpoetry


[PHP] SimpleXML: convert xml to text

2010-03-14 Thread Dasn


Hello, I want to convert some xml stuff to simple string using php, say:

?php

$string = XML
a left foocenter1okok/okcenter2/fooright /a
XML;

$xml = simplexml_load_string($string);
echo $xml;
?
The code will output left right while all the central stuff was lost.
How should I print it as left center1 ok center2 right ?

Thanks in advance, and please Cc me. :)

--
Dasn


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML: convert xml to text

2010-03-14 Thread Ashley Sheridan
On Sun, 2010-03-14 at 21:58 +0800, Dasn wrote:

 Hello, I want to convert some xml stuff to simple string using php, say:
 
 ?php
 
 $string = XML
 a left foocenter1okok/okcenter2/fooright /a
 XML;
 
 $xml = simplexml_load_string($string);
 echo $xml;
 ?
 The code will output left right while all the central stuff was lost.
 How should I print it as left center1 ok center2 right ?
 
 Thanks in advance, and please Cc me. :)
 
 -- 
 Dasn
 
 


Can't you just call strip_tags() on the string? As you don't need to
echo any attribute values, I would have thought it would be perfect. As
XML is meant to be well-formed anyway, strip_tags shouldn't cause any
problems with broken or missing closing tags.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] SimpleXML: convert xml to text

2010-03-14 Thread Dasn

On Sun, 14 Mar 2010 22:02:22 +0800, Ashley Sheridan wrote:


On Sun, 2010-03-14 at 21:58 +0800, Dasn wrote:


Hello, I want to convert some xml stuff to simple string using php, say:

?php

$string = XML
a left foocenter1okok/okcenter2/fooright /a
XML;

$xml = simplexml_load_string($string);
echo $xml;
?
The code will output left right while all the central stuff was lost.
How should I print it as left center1 ok center2 right ?

Thanks in advance, and please Cc me. :)




Can't you just call strip_tags() on the string? As you don't need to
echo any attribute values, I would have thought it would be perfect. As
XML is meant to be well-formed anyway, strip_tags shouldn't cause any
problems with broken or missing closing tags.


Thanks Ashley for your reply.
Sorry that my description was not clear enough.
Actually I don't want to just strip the tags, sometimes I also wanna  
change some elements. For another example:  
ablafunctionstrip_tags/functionbla/a. When output, I also want  
to make some change to the data depending on the tags, say, trying to  
append a pair of () to the function element, printing it as bla  
strip_tags() bla.
The problem is when I processing the nodes with SimpleXML, I couldn't get  
the right order of the data. That is :
echo $xml-a, (string) $xml-a-function . '()' // prints bla bla  
strip_tags()


Thank you anyway. Cc please.

--
Dasn


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML: convert xml to text

2010-03-14 Thread Dasn

On Sun, 14 Mar 2010 22:02:22 +0800, Ashley Sheridan wrote:


On Sun, 2010-03-14 at 21:58 +0800, Dasn wrote:


Hello, I want to convert some xml stuff to simple string using php, say:

?php

$string = XML
a left foocenter1okok/okcenter2/fooright /a
XML;

$xml = simplexml_load_string($string);
echo $xml;
?
The code will output left right while all the central stuff was lost.
How should I print it as left center1 ok center2 right ?

Thanks in advance, and please Cc me. :)



Well I change to use xmlparser instead, never mind. :)

--
Dasn


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-08 Thread Ashley Sheridan
On Sun, 2010-02-07 at 23:24 -0800, TerryA wrote:

 Hi Carlos
 
 I looked at the documentation for hours but don't see any solution. I'm
 uploading a sample file here. The full file contains around 100 properties
 but the uploaded file has just one. I need to extract data from this file to
 write to a MySQL database. I have no problem in doing this until it comes to
 the elements-element tags. I only need 3 of these elements. I can
 extract the data by iteration but that does not help me to get the three
 specific element tags that I need because there are some tags that appear
 for some properties and not for others so the order is different. Here is
 the file:
 http://old.nabble.com/file/p27496211/annnonces.xml annnonces.xml 
 Thanks
 Terry
 
 
 
 -- 
 View this message in context: 
 http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27496211.html
 Sent from the PHP - General mailing list archive at Nabble.com.
 
 


As you iterate the elements tags, check their attributes with
getAttribute().

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] simplexml - can it do what I need?

2010-02-08 Thread TerryA

Hi Guys

Thanks for all your input. This forum is great! I can get the attributes OK
but I can't code the checking routing correctly. This is what I have:

Many thanks again for your input. I tried this but it only gives me the data
for each element. I need to be able to access the attributes of the data in
order to select only those elements that I need. This is the code that I
have at present:

?php
$file= 'annnonces.xml';
// load file
$xml = simplexml_load_file($file) or die (Unable to load XML file!);
foreach ($xml-xpath('//lot') as $lot) {
echo $lot-numero_lot, 'type ', $lot-type, $lot-identification, 'br
/';
echo 'Prix maxi: ', $lot-tarif_max, ' Prix mini: ', $lot-tarif_min,
'br /';
foreach( $lot-elements-element as $key = $data ){
$result=((string) $data-attributes());
if ($result='17') {
  echo $data;
}
}
}
?

But this just gives the data for every element. Any ideas on how to get just
the data for the element when the attribute is 17?

Terry
-- 
View this message in context: 
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27496987.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-08 Thread TerryA

Got it! I corrected my syntax and this code now works as far as I can tell:

?php
$file= 'annnonces.xml';
// load file
$xml = simplexml_load_file($file) or die (Unable to load XML file!);
foreach ($xml-xpath('//lot') as $lot) {
echo $lot-numero_lot, 'type ', $lot-type, $lot-identification, 'br
/';
echo 'Prix maxi: ', $lot-tarif_max, ' Prix mini: ', $lot-tarif_min,
'br /';
foreach( $lot-elements-element as $key = $data ){
$result=((string) $data-attributes());
if ($result == 1) {
echo Nombre pièces: , $data, 'br /';
}
if ($result == 3) {
echo Surface: , $data, m2, 'br /';
}
if ($result == 7) {
echo Nombre étoiles: , $data, 'br /';
break;
}
}
}
?

Output is:
201type APPARTEMENT STUDIOTEE2 106
Prix maxi: 475 Prix mini: 475
Nombre pièces: 1
Surface: 27m2
Nombre étoiles: 3

Hooray and thanks to all of you guys.

Terry
-- 
View this message in context: 
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27500759.html
Sent from the PHP - General mailing list archive at Nabble.com.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-07 Thread TerryA

Hi Shawn
Thanks for answering my query. I have looked at the suggestions:

$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

I am/was able to load the file OK and to access the data by iteration.
However, I can't find a way to extract data by attributes. I need something
like $string=element idtype=11 lang=fr label=Description - Etage.
Obviously, that won't work but that's the result I need. How do I get the
data out of one of these elements by specifying its idtype and lang? I've
google for hours on this and for another hour on SimpleXMLElement.

Terry
-- 
View this message in context: 
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27486649.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-07 Thread Carlos Medina

TerryA schrieb:

Hi Shawn
Thanks for answering my query. I have looked at the suggestions:

$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

I am/was able to load the file OK and to access the data by iteration.
However, I can't find a way to extract data by attributes. I need something
like $string=element idtype=11 lang=fr label=Description - Etage.
Obviously, that won't work but that's the result I need. How do I get the
data out of one of these elements by specifying its idtype and lang? I've
google for hours on this and for another hour on SimpleXMLElement.

Terry

Hi Terry,
look at the PHP.NET documentation. There indicates the use of 
simpleXMLElement structures. If you want to extract elements from this 
object, please read there how this work. By the way, it would be 
interesting to see, how your XML is made. May be is usefull to use 
another class like DOM.


regards

carlos


http://de2.php.net/manual/fr/book.simplexml.php
http://de2.php.net/manual/fr/refs.xml.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-07 Thread TerryA

Hi Carlos

I looked at the documentation for hours but don't see any solution. I'm
uploading a sample file here. The full file contains around 100 properties
but the uploaded file has just one. I need to extract data from this file to
write to a MySQL database. I have no problem in doing this until it comes to
the elements-element tags. I only need 3 of these elements. I can
extract the data by iteration but that does not help me to get the three
specific element tags that I need because there are some tags that appear
for some properties and not for others so the order is different. Here is
the file:
http://old.nabble.com/file/p27496211/annnonces.xml annnonces.xml 
Thanks
Terry



-- 
View this message in context: 
http://old.nabble.com/simplexml---can-it-do-what-I-need--tp27481222p27496211.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml - can it do what I need?

2010-02-06 Thread Shawn McKenzie
TerryA wrote:
 My first post and I'm just a few days into learning PHP so that I can extract
 data from an XML feed for updating a MySQL driven website. Simplexml grabs
 most of my data without a problem but I can't get at the data in elements
 such as: 
 element idtype=11 lang=fr label=Description - Etage![CDATA[Rez de
 jardin]]/element
 element idtype=1 lang=fr label=Description - Nombre de
 pièces![CDATA[1]]/element
 element idtype=2 lang=fr label=Description - Nombre de
 chambres![CDATA[0]]/element
 element idtype=3 lang=fr label=Description - Surface totale
 (m²)![CDATA[27]]/element
 I have around a hundred of these elements but only need data from two of
 them. I need to extract the CDATA by specifying the idtype and lang
 attribute. For example, in the first of these elements, I need to be able to
 get out the string Rez de jardin by specifying idtype=11 and lang=fr.
 Can I use Simplexml to do this and, if so, how? If not, what should I use?
 Many thanks for any help.
 Terry

Look at the options:

$xml = simplexml_load_file('file.xml', 'SimpleXMLElement', LIBXML_NOCDATA);

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML or DOMDocument help

2009-12-09 Thread Michael Alaimo
Hello All,

I have an XML document that has elements as such:
Query:Expression
  Query:ResourceID
Query:EqualTest/Query:Equal
  /Query:ResourceID
/Query:Expression


I cannot figure out how to access these with simple xml.  I am not opposed
to a DOMDocument solution either.

Would anyone know what to do in this case?  I think the problem is the :.

Regards,

Mike




*
Michael Alaimo
ADNET Systems, Inc.
Web Developer
Work: 301-286-5569
Cell: 571-332-9210
*



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML var_dump() weirdness

2009-10-13 Thread Mattias Thorslund

Hi,

It seems that var_dump() of a SimpleXMLElement does not show an 
attribute of elements that contain text content?


I hope my examples might show what I mean:

$xml = 'root rootattr=root valueinner attr=value//root';
$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

This results in:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 object(SimpleXMLElement)#2 (1) {
   [@attributes]=
   array(1) {
 [attr]=
 string(5) value
   }
 }
}
?xml version=1.0?
root rootattr=root valueinner attr=value//root

...and that's fine, though it would have been nice to also know that the 
root element is called root.


The second example manifests the weirdness:

$xml = 'root rootattr=root valueinner 
attr=valuetext/inner/root';

$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 string(4) text
}
?xml version=1.0?
root rootattr=root valueinner attr=valuetext/inner/root

Notice that the attribute attr of the element inner is not displayed.

In the third case, I replace the content of the inner element with 
another element:


$xml = 'root rootattr=root valueinner 
attr=valuedeep//inner/root';

$simple = new SimpleXMLElement($xml);
var_dump($simple);
echo $simple-asXML();

Outputs:

object(SimpleXMLElement)#1 (2) {
 [@attributes]=
 array(1) {
   [rootattr]=
   string(10) root value
 }
 [inner]=
 object(SimpleXMLElement)#2 (2) {
   [@attributes]=
   array(1) {
 [attr]=
 string(5) value
   }
   [deep]=
   object(SimpleXMLElement)#3 (0) {
   }
 }
}
?xml version=1.0?
root rootattr=root valueinner attr=valuedeep//inner/root

The invisible attributes are still accessible with xpath(), etc (the 
asXML() dump shows that it is still present, but just not visible. This 
might be a bug? Or am I just not understanding something?


Cheers,

Mattias
PHP 5.2.6

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML Class

2009-05-06 Thread Cesco
Could you help me clarify one thing that I don't understand... let's  
put it simple, just imagine that I have a tiny XML document with a  
list of movies:


movies
title
iGone/i with bthe/b wind
/title
/movies

I want to read this XML file and write the name of the first (and  
only) movie in the list; for this reason I have choose to use  
SimpleXML since it was looking quite user-friendly.


But there's a thing I don't understand... when I have some children,  
how do I understand which is the first child and which is the last ? I  
have tried to write this, but I'm getting a wrong result: instead of  
Gone with the wind I got with wind Gone the, because I understand  
that the tag title contains all the text that is not formatted, and  
then it writes all the children of title: iGone/i and bthe/b


?php

	$xml = new SimpleXMLElement(moviestitleiGone/i with bthe/ 
b wind/title/movies);


echo ($xml-title .  );
foreach ($xml-title-children() as $element) {
echo ($element .  );
}

// Returns with wind Gone the

?

I'm using PHP 5.2.5, could you tell me what am I doing wrong ? Thank you

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML output encoding

2009-05-05 Thread Ondrej Kulaty
Hi,
is there any way how to set output encoding for SimpleXML?
It will load XML document in any encoding, but internally, it converts the 
document to UTF-8 and outputs it in this encoding.
I would like to have output encoding set to ISO-8859-2, is it possible? 
thanks.

-- 
Ondrej Kulaty 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML output encoding

2009-05-05 Thread tedd

At 2:40 PM +0200 5/5/09, Ondrej Kulaty wrote:

Hi,
is there any way how to set output encoding for SimpleXML?
It will load XML document in any encoding, but internally, it converts the
document to UTF-8 and outputs it in this encoding.
I would like to have output encoding set to ISO-8859-2, is it possible?
thanks.

--
Ondrej Kulaty


Why?

http://www.cl.cam.ac.uk/~mgk25/unicode.html

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML output encoding

2009-05-05 Thread Ondrej Kulaty
Because i am working on an old system which is in ISO, i cant use unicode.

--
Ondrej Kulaty

tedd tedd.sperl...@gmail.com píse v diskusním príspevku 
news:p06240802c625f6b4e...@[192.168.1.101]...
 At 2:40 PM +0200 5/5/09, Ondrej Kulaty wrote:
Hi,
is there any way how to set output encoding for SimpleXML?
It will load XML document in any encoding, but internally, it converts the
document to UTF-8 and outputs it in this encoding.
I would like to have output encoding set to ISO-8859-2, is it possible?
thanks.

--
Ondrej Kulaty

 Why?

 http://www.cl.cam.ac.uk/~mgk25/unicode.html

 tedd

 -- 
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with PHP simplexml and doxygen generated XML

2009-04-05 Thread hessiess


 On Apr 3, 2009, at 17:52, hessi...@hessiess.com wrote:

 I have bean trying to right a PHP script to generate XHTML code from
 the
 class documentation xml files created by Doxygen(the HTML it outputs
 is
 invalid, messy and virtually imposable to integrate into another web
 page). One thing has bean causing problems, the tags which start
 with `@',
 for example:

 Code:
  SimpleXMLElement Object
  (
[...@attributes] = Array
(
[kind] = function
[id] = classhello_1f06929bd13d07b414a8be07c6db88074
[prot] = private
[static] = no
[const] = no
[explicit] = no
[inline] = yes
[virt] = non-virtual
)
  ...

 I cannot seam to find a way to access these with simplexml, the
 following
 code generates a syntax error for example.

 Code:

 print_r($xml-compounddef-sectiondef-memberdef[1]-@attributes);

 Any advice would be gratily appreciated.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 What about first stripping out the @ characters with str_replace and
 then attempting to load the XML? Maybe run it thru a few to do the
 best possible clean up?

 Bastien


Found out what I was doing wrong, the problem has nothing to do with the
XML code, tag attributes are put into the @attributes section, which must
be accsessed with the attributes() function.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with PHP simplexml and doxygen generated XML

2009-04-05 Thread Andrew Williams
I HAVE THE SAME PROBLEM, PLEASE HOW HAVE YOU DONE IT

On Sun, Apr 5, 2009 at 4:08 PM, hessi...@hessiess.com wrote:

 
 
  On Apr 3, 2009, at 17:52, hessi...@hessiess.com wrote:
 
  I have bean trying to right a PHP script to generate XHTML code from
  the
  class documentation xml files created by Doxygen(the HTML it outputs
  is
  invalid, messy and virtually imposable to integrate into another web
  page). One thing has bean causing problems, the tags which start
  with `@',
  for example:
 
  Code:
   SimpleXMLElement Object
   (
 [...@attributes] = Array
 (
 [kind] = function
 [id] = classhello_1f06929bd13d07b414a8be07c6db88074
 [prot] = private
 [static] = no
 [const] = no
 [explicit] = no
 [inline] = yes
 [virt] = non-virtual
 )
   ...
 
  I cannot seam to find a way to access these with simplexml, the
  following
  code generates a syntax error for example.
 
  Code:
 
  print_r($xml-compounddef-sectiondef-memberdef[1]-@attributes);
 
  Any advice would be gratily appreciated.
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  What about first stripping out the @ characters with str_replace and
  then attempting to load the XML? Maybe run it thru a few to do the
  best possible clean up?
 
  Bastien
 

 Found out what I was doing wrong, the problem has nothing to do with the
 XML code, tag attributes are put into the @attributes section, which must
 be accsessed with the attributes() function.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Best Wishes
Andrew Williams


Re: [PHP] problem with PHP simplexml and doxygen generated XML

2009-04-05 Thread hessiess
 I HAVE THE SAME PROBLEM, PLEASE HOW HAVE YOU DONE IT

 On Sun, Apr 5, 2009 at 4:08 PM, hessi...@hessiess.com wrote:

 
 
  On Apr 3, 2009, at 17:52, hessi...@hessiess.com wrote:
 
  I have bean trying to right a PHP script to generate XHTML code from
  the
  class documentation xml files created by Doxygen(the HTML it outputs
  is
  invalid, messy and virtually imposable to integrate into another web
  page). One thing has bean causing problems, the tags which start
  with `@',
  for example:
 
  Code:
   SimpleXMLElement Object
   (
 [...@attributes] = Array
 (
 [kind] = function
 [id] = classhello_1f06929bd13d07b414a8be07c6db88074
 [prot] = private
 [static] = no
 [const] = no
 [explicit] = no
 [inline] = yes
 [virt] = non-virtual
 )
   ...
 
  I cannot seam to find a way to access these with simplexml, the
  following
  code generates a syntax error for example.
 
  Code:
 
  print_r($xml-compounddef-sectiondef-memberdef[1]-@attributes);
 
  Any advice would be gratily appreciated.
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
  What about first stripping out the @ characters with str_replace and
  then attempting to load the XML? Maybe run it thru a few to do the
  best possible clean up?
 
  Bastien
 

 Found out what I was doing wrong, the problem has nothing to do with the
 XML code, tag attributes are put into the @attributes section, which
 must
 be accsessed with the attributes() function.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




 --
 Best Wishes
 Andrew Williams


Just use the attributes() function, for example:
$xml-compounddef-sectiondef-memberdef[0]-attributes()-kind

Also, no need to shout ;)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] problem with PHP simplexml and doxygen generated XML

2009-04-03 Thread hessiess
I have bean trying to right a PHP script to generate XHTML code from the
class documentation xml files created by Doxygen(the HTML it outputs is
invalid, messy and virtually imposable to integrate into another web
page). One thing has bean causing problems, the tags which start with `@',
for example:

Code:
  SimpleXMLElement Object
  (
[...@attributes] = Array
(
[kind] = function
[id] = classhello_1f06929bd13d07b414a8be07c6db88074
[prot] = private
[static] = no
[const] = no
[explicit] = no
[inline] = yes
[virt] = non-virtual
)
  ...

I cannot seam to find a way to access these with simplexml, the following
code generates a syntax error for example.

Code:

print_r($xml-compounddef-sectiondef-memberdef[1]-@attributes);

Any advice would be gratily appreciated.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem with PHP simplexml and doxygen generated XML

2009-04-03 Thread Phpster



On Apr 3, 2009, at 17:52, hessi...@hessiess.com wrote:

I have bean trying to right a PHP script to generate XHTML code from  
the
class documentation xml files created by Doxygen(the HTML it outputs  
is

invalid, messy and virtually imposable to integrate into another web
page). One thing has bean causing problems, the tags which start  
with `@',

for example:

Code:
 SimpleXMLElement Object
 (
   [...@attributes] = Array
   (
   [kind] = function
   [id] = classhello_1f06929bd13d07b414a8be07c6db88074
   [prot] = private
   [static] = no
   [const] = no
   [explicit] = no
   [inline] = yes
   [virt] = non-virtual
   )
 ...

I cannot seam to find a way to access these with simplexml, the  
following

code generates a syntax error for example.

Code:

print_r($xml-compounddef-sectiondef-memberdef[1]-@attributes);

Any advice would be gratily appreciated.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



What about first stripping out the @ characters with str_replace and  
then attempting to load the XML? Maybe run it thru a few to do the  
best possible clean up?


Bastien 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML

2009-02-24 Thread Alex Chamberlain
Hi,

I am trying to write a PHP interface to ISBNdb.com. When I make a certain
request, the following is returned

ISBNdb server_time=2009-02-24T18:57:31Z
 BookList total_results=1 page_size=10 page_number=1
shown_results=1
  BookData book_id=language_proof_and_logic isbn=157586374X
isbn13=9781575863740
   TitleLanguage, Proof and Logic/Title
   TitleLong/TitleLong
   AuthorsTextJon Barwise, John Etchemendy, /AuthorsText
   PublisherText publisher_id=center_for_the_study_of_la_a03Center for
the Study of Language and Inf/PublisherText
   Subjects
Subject
subject_id=amazon_com_nonfiction_philosophy_logic_languageAmazon.com --
Nonfiction -- Philosophy -- Logic amp; Language/Subject
Subject subject_id=amazon_com_science_generalAmazon.com -- Science
-- General/Subject
   /Subjects
  /BookData
 /BookList
/ISBNdb

And when loaded using simplexml_load_string, it gives the following object

object(SimpleXMLElement)#10 (2) {
[@attributes]=
array(1) {
  [server_time]=
  string(20) 2009-02-24T18:57:31Z
}
[BookList]=
object(SimpleXMLElement)#14 (2) {
  [@attributes]=
  array(4) {
[total_results]=
string(1) 1
[page_size]=
string(2) 10
[page_number]=
string(1) 1
[shown_results]=
string(1) 1
  }
  [BookData]=
  object(SimpleXMLElement)#11 (6) {
[@attributes]=
array(3) {
  [book_id]=
  string(24) language_proof_and_logic
  [isbn]=
  string(10) 157586374X
  [isbn13]=
  string(13) 9781575863740
}
[Title]=
string(25) Language, Proof and Logic
[TitleLong]=
object(SimpleXMLElement)#15 (0) {
}
[AuthorsText]=
string(30) Jon Barwise, John Etchemendy, 
[PublisherText]=
string(40) Center for the Study of Language and Inf
[Subjects]=
object(SimpleXMLElement)#16 (1) {
  [Subject]=
  array(2) {
[0]=
string(58) Amazon.com -- Nonfiction -- Philosophy -- Logic 
Language
[1]=
string(32) Amazon.com -- Science -- General
  }
}
  }
}

Notice that I lose the attribute subject_id from the Subject tag. Why is
this?? Is there any way from preventing it from happening??

Thanks in advance,

Alex Chamberlain


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML - issue with getting data out of the object returned

2008-12-18 Thread Dan Joseph
Hi,

I have a basic XML document that I am grabbing with simplexml_load_string(),
here is the print_r:

SimpleXMLElement Object
(
[Package] = SimpleXMLElement Object
(
[PackageID] = 804
[PackageName] = Silver
[BandwidthGB] = 20
[WebStorageMB] = 5120
[DBStorageMB] = 250
[POPMailBoxes] = 50
[WebStorageUnits] = 5
[BandwidthUnits] = 1
[DBStorageUnits] = 1
[POPUnits] = 5
[DomainHeaders] = 50
[DBType] = MSSQL
[OSType] = Windows
[Enabled] = True
)

[Count] = 1
)

When I try and access $x-Package-PackageID I don't get 804, I get:

SimpleXMLElement Object
(
[0] = 804
)

Could someone tell me how I just get the value 804 out of there?

-- 
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.


Re: [PHP] SimpleXML - issue with getting data out of the object returned

2008-12-18 Thread German Geek
Tim-Hinnerk Heuer

http://www.ihostnz.com


On Fri, Dec 19, 2008 at 3:50 PM, Dan Joseph dmjos...@gmail.com wrote:

 Hi,

 I have a basic XML document that I am grabbing with
 simplexml_load_string(),
 here is the print_r:

 SimpleXMLElement Object
 (
[Package] = SimpleXMLElement Object
(
[PackageID] = 804
[PackageName] = Silver
[BandwidthGB] = 20
[WebStorageMB] = 5120
[DBStorageMB] = 250
[POPMailBoxes] = 50
[WebStorageUnits] = 5
[BandwidthUnits] = 1
[DBStorageUnits] = 1
[POPUnits] = 5
[DomainHeaders] = 50
[DBType] = MSSQL
[OSType] = Windows
[Enabled] = True
)

[Count] = 1
 )

 When I try and access $x-Package-PackageID I don't get 804, I get:

 SimpleXMLElement Object
(
[0] = 804
)

Had that problem before:
$val = (string) $x-Package-PackageID;
or
$val = (int) $x-Package-PackageID;

or whatever type you want. ;)


 Could someone tell me how I just get the value 804 out of there?

 --
 -Dan Joseph

 www.canishosting.com - Plans start @ $1.99/month.

 Build a man a fire, and he will be warm for the rest of the day.
 Light a man on fire, and will be warm for the rest of his life.



Re: [PHP] SimpleXML - issue with getting data out of the object returned

2008-12-18 Thread Dan Joseph
On Thu, Dec 18, 2008 at 10:01 PM, German Geek geek...@gmail.com wrote:

 $val = (string) $x-Package-PackageID;
 or
 $val = (int) $x-Package-PackageID;


Ha... I would have never figured that out...  Thank you to you both!  That
did the trick.

-- 
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.


[PHP] Simplexml encodes output xml

2008-11-05 Thread Manoj Singh
Hi All,
I am using PHP's senderxml library to generate the xml. My problem is that
xml generated by this library encode some characters like ,  etc. Since i
have to give the output xml to the device so i don't want to encode these
characters.

I know there is html_entity_decode method which can decode these characters.
But I want to confirm that whether this method is decoding all characters or
i need to use some other method for that? Also if there any parameter in
senderxml library which tells this library not to encode the output xml.

Any help will be appreciated.

Regards,
Manoj Kumar Singh


[PHP] SimpleXML strange behaviour.

2008-09-09 Thread Mirco Soderi
Do you know any reason why the following code does work


$xmlOperazioni = simplexml_load_file($xmlFilename);
foreach($xmlOperazioni-operazione as $operazione) {
   if($operazione['nome'] == $operazioneRichiesta) {
  require($operazione['php']);
  break;
   }
}

but the following does not

$xmlOperazioni = 
simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_operazioni']);
foreach($xmlOperazioni-operazione as $operazione) {
   if($operazione-nome == $operazioneRichiesta) {
  require($operazione-php);
  break;
   }
}

that is I MUST access childrens of the element operazione as if it was an 
array, while (in the same page) the following code does work

$xmlViste = 
simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_composizione_viste']);
foreach($xmlViste-vista as $vista) {
if($vista-nome == $nomeVistaDaMostrare) {
   $smarty-assign(intestazione,componenti/.$vista-intestazione);
   $smarty-assign(menu,componenti/.$vista-menu);
   $smarty-assign(contenuto, componenti/.$vista-contenuto);
   $smarty-assign(pie_di_pagina, componenti/.$vista-pie_di_pagina);
   break;
}
}

but the following does not

$xmlViste = 
simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_composizione_viste']);
foreach($xmlViste-vista as $vista) {
if($vista['nome'] == $nomeVistaDaMostrare) {
   $smarty-assign(intestazione,componenti/.$vista['intestazione']);
   $smarty-assign(menu,componenti/.$vista['menu']);
   $smarty-assign(contenuto, componenti/.$vista['contenuto']);
   $smarty-assign(pie_di_pagina, componenti/.$vista['pie_di_pagina']);
   break;
}
}

that is this time I MUST access the childrens of the element operazione as if 
it was an object?

Re: [PHP] SimpleXML strange behaviour.

2008-09-09 Thread Nathan Nobbe
2008/9/9 Mirco Soderi [EMAIL PROTECTED]

 Do you know any reason why the following code does work


 $xmlOperazioni = simplexml_load_file($xmlFilename);
 foreach($xmlOperazioni-operazione as $operazione) {
   if($operazione['nome'] == $operazioneRichiesta) {
  require($operazione['php']);
  break;
   }
 }

 but the following does not

 $xmlOperazioni =
 simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_operazioni']);
 foreach($xmlOperazioni-operazione as $operazione) {
   if($operazione-nome == $operazioneRichiesta) {
  require($operazione-php);
  break;
   }
 }


well im guessing thats because youre using the same file and different
accessors, what i mean is that if
$xmlFilename, and
$impostazioni['root']['configurazione']['generale']['xml_operazioni'] refer
to the same xml from above, then obviously this wont work..

this is looking for an attribute, 'nome', $operazione['nome'];
this is looking for a child element, 'nome', $operazione-nome

that is I MUST access childrens of the element operazione as if it was an
 array, while (in the same page) the following code does work

 $xmlViste =
 simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_composizione_viste']);
 foreach($xmlViste-vista as $vista) {
if($vista-nome == $nomeVistaDaMostrare) {
   $smarty-assign(intestazione,componenti/.$vista-intestazione);
   $smarty-assign(menu,componenti/.$vista-menu);
   $smarty-assign(contenuto, componenti/.$vista-contenuto);
   $smarty-assign(pie_di_pagina,
 componenti/.$vista-pie_di_pagina);
   break;
}
 }

 but the following does not

 $xmlViste =
 simplexml_load_file($impostazioni['root']['configurazione']['generale']['xml_composizione_viste']);
 foreach($xmlViste-vista as $vista) {
if($vista['nome'] == $nomeVistaDaMostrare) {
   $smarty-assign(intestazione,componenti/.$vista['intestazione']);
   $smarty-assign(menu,componenti/.$vista['menu']);
   $smarty-assign(contenuto, componenti/.$vista['contenuto']);
   $smarty-assign(pie_di_pagina,
 componenti/.$vista['pie_di_pagina']);
   break;
}
 }


again, this syntax denotes a child element,
$vista-nome
this syntax denotes an attribute
$vista['nome']

that is this time I MUST access the childrens of the element operazione as
 if it was an object?


i recommend a review of the example page on simple xml, but yes children are
access via the - notation, you can also use the children() method if its
more convenient for you.

http://us2.php.net/manual/en/simplexml.examples.php

-nathan


[PHP] simplexml

2008-07-10 Thread Joakim Ling
Hi 

 

I'm using simplexml to create some xml files.

Here's a stripped example, how can I get this to work? Tried millions
different ways still no joy.

 

?php

header(Content-type: text/xml);

 

$xml = simplexml_load_string('root/root');

$root = $xml-addChild('tests');

$root-addChild('test', 'test  test');

 

echo $xml-asXML();

?

 

// cheers jo



Re: [PHP] simplexml

2008-07-10 Thread Nate Tallman
You have to handle the html special chars.

 == amp;



On Thu, Jul 10, 2008 at 10:59 AM, Joakim Ling [EMAIL PROTECTED] wrote:

 Hi



 I'm using simplexml to create some xml files.

 Here's a stripped example, how can I get this to work? Tried millions
 different ways still no joy.



 ?php

 header(Content-type: text/xml);



 $xml = simplexml_load_string('root/root');

 $root = $xml-addChild('tests');

 $root-addChild('test', 'test  test');



 echo $xml-asXML();

 ?



 // cheers jo




Re: [PHP] simplexml

2008-07-10 Thread Nate Tallman
You have to handle the html special chars.

 == amp;



On Thu, Jul 10, 2008 at 10:59 AM, Joakim Ling [EMAIL PROTECTED] wrote:

 Hi



 I'm using simplexml to create some xml files.

 Here's a stripped example, how can I get this to work? Tried millions
 different ways still no joy.



 ?php

 header(Content-type: text/xml);



 $xml = simplexml_load_string('root/root');

 $root = $xml-addChild('tests');

 $root-addChild('test', 'test  test');



 echo $xml-asXML();

 ?



 // cheers jo




Re: [PHP] simplexml

2008-07-10 Thread Nathan Nobbe
On Thu, Jul 10, 2008 at 10:55 AM, Nate Tallman 
[EMAIL PROTECTED] wrote:

 You have to handle the html special chars.

  == amp;


and if you use the SimpleXMLElement constructor, it will throw an exception,
rather than just return false, which is useful, because it tells you what
went wrong.

-nathan


[PHP] SimpleXML and registerXPathNamespace

2008-06-13 Thread Mario Caprino
Hi,

I am having problems with the below test case. I am using an extended
googlebase Atom format to store my data.  Included in the test case is
a simplified version of my XML-document.

PROBLEM:
Why do I need to re-register namespace 'a' when using xpath through
the result of a previous xpath()-statement?
As you may notice the same is not true for namespace 'g'.
I can't get this to make sense!

Any insight would be much appreciated.

Best regards,
Mario Caprino

?php
#Simpliefied sample data
$str= EOF
?xml version=1.0 encoding=iso-8859-1?
feed xmlns=http://www.w3.org/2005/Atom;
xmlns:g=http://base.google.com/ns/1.0;
xml:lang=en
entry
   g:mpn10100/g:mpn
   titleMy product/title
   title xml:lang=noMitt produkt/title
   g:price299/g:price
/entry
/feed
EOF;

#Load document
$xml= simplexml_load_string ($str);
$xml-registerXPathNamespace ('a', 'http://www.w3.org/2005/Atom');
$xml-registerXPathNamespace ('g', 'http://base.google.com/ns/1.0');

echo This is what I am trying to achieve...\n;
$lang= 'no';
$id= '10100';
$title= $xml-xpath (/a:feed/a:entry[g:mpn='$id']/a:title[lang('$lang')]);
echo utf8_decode ($title[0]) . \n;

#---

echo But I'd fist like to store the entity node, and then request
several data nodes relative to it\n;
$entry= $xml-xpath (/a:feed/a:entry[g:mpn='$id']);
$entry= $entry[0];


$price= $entry-xpath (g:price);
echo This works as expected: $price[0]\n;

#$entry-registerXPathNamespace ('a', 'http://www.w3.org/2005/Atom');
$title= $entry-xpath (a:title[lang('$lang')]);
echo '... but this will only work if I re-register the namespace a?
' . utf8_decode ($title[0]);
?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML addChild() namespace problem

2008-01-18 Thread Nathan Nobbe
On Jan 18, 2008 12:04 PM, Carole E. Mah [EMAIL PROTECTED] wrote:

 I did exactly this, and still got:

 ?xml version=1.0 encoding=UTF-8?
 rss xmlns:itunes=http://www.itunes.com/dtds/podcast-1.0.dtd; version=
 2.0
channel
!-- snipping, some elements omitted ... --
item
titleMy Title/title
linkMy Link/link
descriptionMy Description/description
itunes:author xmlns:itunes=itunesMy
 Author/itunes:author
itunes:subtitle xmlns:itunes=itunesMy
 Subtitle/itunes:subtitle
!-- snipping, more elements omitted ... --
/item
/channel
 /rss



are you trying to read an existing document into a SimpleXMLElement, or are
you trying
to create a SimpleXMLElement instance and generate a document from that?
my impression was you were trying to do the later; please clarify and if you
are trying to
do the later, post the code you are using to create the SimpleXMLElement
instance and
generate the output youve posted.

-nathan


Re: [PHP] SimpleXML addChild() namespace problem

2008-01-18 Thread Carole E. Mah
On Jan 18, 2008 12:22 PM, Nathan Nobbe [EMAIL PROTECTED] wrote:
 Are you trying to read an existing document into a SimpleXMLElement, or are
 you trying to create a SimpleXMLElement instance and generate a document
 from that?
 My impression was you were trying to do the later; please clarify and if you
 are trying to do the later, post the code you are using to create the
 SimpleXMLElement instance and generate the output youve posted.

Nathan,

I am trying to to the latter -- create a SimpleXMLElement instance and generate
a document from that.

Thank you very much for all your examples and patience.

I now see the very silly mistake I made.

Correct (from your example):

$xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
$n = $xml-addChild(subtitle, Musical Mockery,  http://apple.com;);

Incorrect (what I was doing):

$xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
$n = $xml-addChild(subtitle, Musical Mockery,  itunes);

To be fair, there really isn't an example of this on PHP.net.
Nonetheless, I feel a bit foolish for having wasted your time with
this. Thank you for your help.

Carole

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML addChild() namespace problem

2008-01-18 Thread Carole E. Mah
based upon information from bug #43221, if you define the namespace
beforehand
it will work.

?php
$xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
$n = $xml-addChild(subtitle, Musical Mockery, http://apple.com;);
print_r($xml-asXml());
?

produces:
?xml version=1.0?
root xmlns:itunes=http://apple.com;itunes:subtitleMusical
Mockery/itunes:subtitle/root

-nathan

Actually, it doesn't work.

I did exactly this, and still got:

?xml version=1.0 encoding=UTF-8?
rss xmlns:itunes=http://www.itunes.com/dtds/podcast-1.0.dtd; version=2.0
channel
!-- snipping, some elements omitted ... --
item
titleMy Title/title
linkMy Link/link
descriptionMy Description/description
itunes:author xmlns:itunes=itunesMy 
Author/itunes:author
itunes:subtitle xmlns:itunes=itunesMy 
Subtitle/itunes:subtitle
!-- snipping, more elements omitted ... --
/item
/channel
/rss

-Carole

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML addChild() namespace problem

2008-01-18 Thread Nathan Nobbe
On Jan 18, 2008 2:48 PM, Carole E. Mah [EMAIL PROTECTED] wrote:

 On Jan 18, 2008 12:22 PM, Nathan Nobbe [EMAIL PROTECTED] wrote:
  Are you trying to read an existing document into a SimpleXMLElement, or
 are
  you trying to create a SimpleXMLElement instance and generate a document
  from that?
  My impression was you were trying to do the later; please clarify and if
 you
  are trying to do the later, post the code you are using to create the
  SimpleXMLElement instance and generate the output youve posted.

 Nathan,

 I am trying to to the latter -- create a SimpleXMLElement instance and
 generate
 a document from that.

 Thank you very much for all your examples and patience.

 I now see the very silly mistake I made.

 Correct (from your example):

 $xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
 $n = $xml-addChild(subtitle, Musical Mockery,  http://apple.com;);

 Incorrect (what I was doing):

 $xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
 $n = $xml-addChild(subtitle, Musical Mockery,  itunes);

 To be fair, there really isn't an example of this on PHP.net.
 Nonetheless, I feel a bit foolish for having wasted your time with
 this. Thank you for your help.


no prob; i learned how to do this on this post myself ;)
glad to hear its working now!

-nathan


Re: [PHP] SimpleXML addChild() namespace problem

2008-01-15 Thread Nathan Nobbe
On Jan 14, 2008 11:21 PM, Carole E. Mah [EMAIL PROTECTED] wrote:

 Yes, I tried the following:

 http://us3.php.net/manual/en/function.dom-domdocument-createelementns.php

 Same results.



based upon information from bug #43221, if you define the namespace
beforehand
it will work.

?php
$xml = new SimpleXMLElement('root xmlns:itunes=http://apple.com/');
$n = $xml-addChild(subtitle, Musical Mockery, http://apple.com;);
print_r($xml-asXml());
?

produces:
?xml version=1.0?
root xmlns:itunes=http://apple.com;itunes:subtitleMusical
Mockery/itunes:subtitle/root

-nathan


Re: [PHP] SimpleXML Bug question

2008-01-15 Thread Richard Lynch
On Tue, January 15, 2008 12:34 am, Naz Gassiep wrote:
 What's the current status on this bug:

 http://bugs.php.net/bug.php?id=39164

 Regardless of what the PHP developers say in those comments, the
 modification of data when it is read is not correct. If it is intended
 behavior, then the developer/s who intend it to be that way are wrong.
 Under no circumstances can it be considered appropriate for any read
 operation to write anything.

 Some clarity on this matter would be great.

The current status is closed as bogus.

I dunno WHY they think it's bogus, but there it is.

Perhaps if you emailed Helly and asked what his thinking was, and
asked politely on php-internals for anybody to comment on why it
should be that way, you'd get a better response.

I don't use XML nor simpleXML enough to really comment, but at first
glance, I'd have to say that the auto-creation of a node is pretty
wrong.

More research might make me change my mind...

Suppose, for example, that the XML spec REQUIRES at least one valid
node, and your XML is malformed without it.

If that were the case, PHP forcing it to be valid by adding a dummy
node seems perfectly reasonable.

You may want to also consider submitting a patch if you really think
it's wrong, and you've managed to find the commit that causes the
problem.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML addChild() namespace problem

2008-01-14 Thread Carole E. Mah
This is problematic code, even though it works, because it
auto-generates an unnecessary xmlns: attribute:

$item-addChild('itunes:subtitle', $mySubTitle,itunes);

It generates the following XML:

itunes:subtitle xmlns:itunes=itunesMusical Mockery/itunes:subtitle

When really all we want is this:

itunes:subtitleMusical Mockery/itunes:subtitle

Furthermore, dumping it into a DomDocument and attempting to use
removeAttributeNS() to remove the spurious attribute removes the
entire kit and kaboodle, leaving only:

subtitleMusical Mockery/subtitle

How can one get the desired result, short of using a regexp? (I have
done this, and it works, but is a silly hack because it doesn't use
XML parsing to address an XML problem).

Thanks,

Carole

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML addChild() namespace problem

2008-01-14 Thread Nathan Nobbe
On Jan 14, 2008 10:22 PM, Carole E. Mah [EMAIL PROTECTED] wrote:

 This is problematic code, even though it works, because it
 auto-generates an unnecessary xmlns: attribute:

 $item-addChild('itunes:subtitle', $mySubTitle,itunes);

 It generates the following XML:

 itunes:subtitle xmlns:itunes=itunesMusical Mockery/itunes:subtitle

 When really all we want is this:

 itunes:subtitleMusical Mockery/itunes:subtitle

 Furthermore, dumping it into a DomDocument and attempting to use
 removeAttributeNS() to remove the spurious attribute removes the
 entire kit and kaboodle, leaving only:

 subtitleMusical Mockery/subtitle

 How can one get the desired result, short of using a regexp? (I have
 done this, and it works, but is a silly hack because it doesn't use
 XML parsing to address an XML problem).


have you considered appending the child w/ w/e the DOM extension
has, just to see if the namespace specification is unintentionally added
by it as well?

-nathan


Re: [PHP] SimpleXML addChild() namespace problem

2008-01-14 Thread Carole E. Mah
Yes, I tried the following:

http://us3.php.net/manual/en/function.dom-domdocument-createelementns.php

Same results.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML Bug question

2008-01-14 Thread Naz Gassiep

What's the current status on this bug:

http://bugs.php.net/bug.php?id=39164

Regardless of what the PHP developers say in those comments, the 
modification of data when it is read is not correct. If it is intended 
behavior, then the developer/s who intend it to be that way are wrong. 
Under no circumstances can it be considered appropriate for any read 
operation to write anything.


Some clarity on this matter would be great.

Regards,
- Naz.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] simplexml problem

2007-12-31 Thread Dani Castaños

Hi all!

I'm using simplexml to load an xml into an object.
The XML is this:
?xml version=1.0?
request
 customerID3/customerID
 appNameagenda/appName
 ticketTypecticket_agenda_server/ticketType
 ticketTypeID1/ticketTypeID
 platformID1/platformID
 ticketActionaddUsersToGroup/ticketAction
/request

When I do this:

$file = simplexml_load_file( 'file.xml' );
$ticketType = $file-ticketType;

What i really have into $ticketType is a SimpleXMLElement... not the 
value cticket_agenda_server... What am I doing wrong?


Because if I echo this value... Yes, I obtain the 
cticket_agenda_server... But if I want to use like:


$ticket = new $ticketType( $param1, $param2);

It throws:
Uncaught exception 'Exception' with message 
'SimpleXMLElement::__construct() expects parameter 1 to be string, array 
given' in C:\Dani\htdocs\ticket_server\ticket_execute.php:134

Stack trace:
#0 C:\Dani\htdocs\ticket_server\ticket_execute.php(134): 
SimpleXMLElement-__construct(Array, Object(clogger))

#1 {main}
 thrown

It seems like it uses $ticketType class instead the value inside.

Than you in advance

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml problem

2007-12-31 Thread Nathan Nobbe
On Dec 31, 2007 7:11 AM, Dani Castaños [EMAIL PROTECTED] wrote:

 Hi all!

 I'm using simplexml to load an xml into an object.
 The XML is this:
 ?xml version=1.0?
 request
  customerID3/customerID
  appNameagenda/appName
  ticketTypecticket_agenda_server/ticketType
  ticketTypeID1/ticketTypeID
  platformID1/platformID
  ticketActionaddUsersToGroup/ticketAction
 /request

 When I do this:

 $file = simplexml_load_file( 'file.xml' );
 $ticketType = $file-ticketType;

 What i really have into $ticketType is a SimpleXMLElement... not the
 value cticket_agenda_server... What am I doing wrong?


cast the value to a string  when you pull it out if you want to use it that
way:

?php
$xml =
XML
?xml version=1.0?
request
 customerID3/customerID
 appNameagenda/appName
 ticketTypecticket_agenda_server/ticketType
 ticketTypeID1/ticketTypeID
 platformID1/platformID
 ticketActionaddUsersToGroup/ticketAction
/request
XML;

$file = new SimpleXMLElement($xml);
$ticketTypeAsSimpleXmlElement = $file-ticketType;
$ticketTypeAsString = (string)$file-ticketType;
$ticketTypeAnalyzer = new ReflectionObject($ticketTypeAsSimpleXmlElement);

echo (string)$ticketTypeAnalyzer . PHP_EOL;
var_dump($ticketTypeAsString);
?

-nathan


Re: [PHP] simplexml problem

2007-12-31 Thread Dani Castaños

Nathan Nobbe escribió:
On Dec 31, 2007 7:11 AM, Dani Castaños [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


Hi all!

I'm using simplexml to load an xml into an object.
The XML is this:
?xml version=1.0?
request
 customerID3/customerID
 appNameagenda/appName
 ticketTypecticket_agenda_server/ticketType
 ticketTypeID1/ticketTypeID
 platformID1/platformID
 ticketActionaddUsersToGroup/ticketAction
/request

When I do this:

$file = simplexml_load_file( 'file.xml' );
$ticketType = $file-ticketType;

What i really have into $ticketType is a SimpleXMLElement... not the
value cticket_agenda_server... What am I doing wrong? 



cast the value to a string  when you pull it out if you want to use it 
that way:


?php
$xml =
XML
?xml version=1.0?
request
 customerID3/customerID
 appNameagenda/appName
 ticketTypecticket_agenda_server/ticketType
 ticketTypeID1/ticketTypeID
 platformID1/platformID
 ticketActionaddUsersToGroup/ticketAction
/request
XML;

$file = new SimpleXMLElement($xml);
$ticketTypeAsSimpleXmlElement = $file-ticketType;
$ticketTypeAsString = (string)$file-ticketType;
$ticketTypeAnalyzer = new 
ReflectionObject($ticketTypeAsSimpleXmlElement);


echo (string)$ticketTypeAnalyzer . PHP_EOL;
var_dump($ticketTypeAsString);
?

-nathan




Thanks! Problem fixed... But I think PHP must do the cast automatically. 
I think it's a bug fixed in a further version than mine as I've read


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml problem

2007-12-31 Thread Nathan Nobbe
On Dec 31, 2007 10:09 AM, Dani Castaños [EMAIL PROTECTED] wrote:

 Thanks! Problem fixed... But I think PHP must do the cast automatically.
 I think it's a bug fixed in a further version than mine as I've read


no problem; but just fyi, its not a bug; the behavior is as expected per the
manual:
http://us3.php.net/manual/en/ref.simplexml.php

*Example#6 Comparing Elements and Attributes with Text*

To compare an element or attribute with a string or pass it into a function
that requires a string,

you must cast it to a string using *(string)*. Otherwise, PHP treats the
element as an object.

if you use an operation that casts implicitly, such as echo, you dont have
to cast yourself;
otherwise you do :)

-nathan


[PHP] SimpleXML error

2007-11-26 Thread Skip Evans

Hey all,

I have some XML files I need to parse and then 
display (they have HTML formatting in them as well).


They contain the following:

?xml version=1.0 ?
!DOCTYPE html PUBLIC -//Gale//DTD Gale eBook 
Document DTD 20031113//EN galeeBkdoc.dtd

html gale:versionNumber=OEB 1.2, Gale 1.3
head
gale:docName gale:zzNumber=2536600565/
gale:documentCitation
gale:pageRange214-215/gale:pageRange
/gale:documentCitation
titleThomas Jefferson and the Revision of the 
Virginia Laws/title

/head

I am then attempting to extract the title with this:

$xml = 
simplexml_load_file(BASE_DIR.'/content/'.$r['filename']);

$title= $xml-title;

But in the browser I get the following warning.

namespace error : Namespace prefix gale for 
versionNumber on html is not defined...


Is this because it is not locating the file 
galeeBkdoc.dtd, which defines all the elements in 
the XML files?


It is located in the same directory as the 
content. I have also tried putting the complete 
path via HTTP in with the name of the DTD file 
with no luck.



Suggestions would be greatly appreciated.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML error

2007-11-26 Thread Casey

I'm not sure, but try casting $xml-title to string, like this:

$title = (string) $xml-title;


On Nov 26, 2007, at 1:44 PM, Skip Evans [EMAIL PROTECTED] wrote:


Hey all,

I have some XML files I need to parse and then display (they have  
HTML formatting in them as well).


They contain the following:

?xml version=1.0 ?
!DOCTYPE html PUBLIC -//Gale//DTD Gale eBook Document DTD  
20031113//EN galeeBkdoc.dtd

html gale:versionNumber=OEB 1.2, Gale 1.3
head
gale:docName gale:zzNumber=2536600565/
gale:documentCitation
gale:pageRange214-215/gale:pageRange
/gale:documentCitation
titleThomas Jefferson and the Revision of the Virginia Laws/title
/head

I am then attempting to extract the title with this:

$xml = simplexml_load_file(BASE_DIR.'/content/'.$r['filename']);
$title= $xml-title;

But in the browser I get the following warning.

namespace error : Namespace prefix gale for versionNumber on html is  
not defined...


Is this because it is not locating the file galeeBkdoc.dtd, which  
defines all the elements in the XML files?


It is located in the same directory as the content. I have also  
tried putting the complete path via HTTP in with the name of the DTD  
file with no luck.



Suggestions would be greatly appreciated.

Thanks!
Skip

--
Skip Evans
Big Sky Penguin, LLC
503 S Baldwin St, #1
Madison, WI 53703
608-250-2720
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and versatile
PHP/MySQL, AJAX  DHTML development framework.
http://phpenguin.bigskypenguin.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SimpleXML end of element/tag error

2007-04-10 Thread Don Don
the code section is displayed below
   
  $xml = simplexml_load_file($_POST['feedurl']);
   
  foreach($xml-TT as $TT) 
{
foreach($TT-TOTS as $TOTS)
{
  $cnt++;
   
foreach($TT-TOTS[$cnt]-attributes() as $a = $b)   // problematic 
line.
{
   
  // DISPLAY THE TITLE AND THE VALUES
//echo  $a $b br/;   
 }
}
}
   
  the error occours when the parser reaches the end of the last element and 
then fires the error
Fatal error: Call to a member function attributes() on a non-object in line 
(see problematic line)
   
  How can i solve that or determine when there are no more tags to parse.

JM Guillermin [EMAIL PROTECTED] wrote:
  And with :

foreach ($xml as $cs) {
.
}
??

jm

- Original Message - 
From: Don Don 

To: PHP List 

Sent: Thursday, April 05, 2007 10:32 AM
Subject: [PHP] SimpleXML end of element/tag error


I am using simple xml to parse an xml file, the program parses the file and 
produces an error at the end of the foreach loop when it reaches the end of 
the tag, it tries to look for an element/tag when there is none and 
produces an error Call to a member function attributes() on a non-object 
the foreach loop looks like this

 foreach($xml-CS as $CS)
 {
 //processing takes place here
 }

 when there are no more CS it fires an error

 How can i detect when there are no more elements/tags to parse and handle 
 it?


 cheers


 -
 It's here! Your new message!
 Get new email alerts with the free Yahoo! Toolbar. 



 
-
Now that's room service! Choose from over 150,000 hotels 
in 45,000 destinations on Yahoo! Travel to find your fit.

[PHP] SimpleXML end of element/tag error

2007-04-05 Thread Don Don
I am using simple xml to parse an xml file, the program parses the file and 
produces an error at the end of the foreach loop when it reaches the end of the 
tag, it tries to look for an element/tag when there is none and produces an 
error Call to a member function attributes() on a non-object the foreach loop 
looks like this
   
  foreach($xml-CS as $CS) 
{
 //processing takes place here
}
   
  when there are no more CS it fires an error
   
  How can i detect when there are no more elements/tags to parse and handle it?
   
  
cheers

 
-
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.

Re: [PHP] SimpleXML end of element/tag error

2007-04-05 Thread JM Guillermin

And with :

foreach ($xml as $cs) {
.
}
??

jm

- Original Message - 
From: Don Don [EMAIL PROTECTED]

To: PHP List php-general@lists.php.net
Sent: Thursday, April 05, 2007 10:32 AM
Subject: [PHP] SimpleXML end of element/tag error


I am using simple xml to parse an xml file, the program parses the file and 
produces an error at the end of the foreach loop when it reaches the end of 
the tag, it tries to look for an element/tag when there is none and 
produces an error Call to a member function attributes() on a non-object 
the foreach loop looks like this


 foreach($xml-CS as $CS)
{
//processing takes place here
}

 when there are no more CS it fires an error

 How can i detect when there are no more elements/tags to parse and handle 
it?



cheers


-
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar. 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML libxml options (XInclude)

2007-02-28 Thread Ben Roberts


Hi there. I'm hoping someone can help me with what I think might be a 
slightly obscure problem.


I'm trying to get the SimpleXML extension to read an XML file and 
process the XInclude statements within the XML file.


The SimpleXML docs state that libxml options may be specified using the 
predefined constants that are available when PHP is compiled with libxml 
support (as it is when you use SimpleXML).

http://uk2.php.net/manual/en/function.simplexml-element-construct.php

So, looking at the libxml options, I see there is a predefined constant 
LIBXML_XINCLUDE which when specified should implement XInclude 
substitution. So my SimpleXML object I define as follows:


  $xml_file = './master.xml';

  $xml = new SimpleXMLElement($xml_file, LIBXML_XINCLUDE, true);

  print_r($xml);

Viewing the resulting datastructure shows me that it has not honoured 
the request to implement the XInclude directives.


Does anyone know if a) I'm using the correct syntax for this, and b) 
have any experience of getting this working.


My master.xml file looks like this:

?xml version=1.0 encoding=UTF-8?
root xmlns:xi=http://www.w3.org/2001/XInclude;
  foossd/foo
  barsss/bar
  xi:include href=a.xml
xi:fallback
  errorxinclude - a.xml not found/error
/xi:fallback
  /xi:include
/root

and then I have a.xml which looks like:

?xml version=1.0 encoding=UTF-8?
a_root
  orangestest/oranges
  applestest more/apples
/a_root

I'm running PHP 5.1.5 with libxml 2.6.20 on Fedora Core 4 linux.

Cheers

Ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SimpleXML is creating nodes when it shouldn't...

2006-05-11 Thread D. Dante Lorenso
I've recently upgraded to PHP 5.1.4 from 5.1.2 and noticed that in 5.1.3 
there were changes made to SimpleXML.  Now, when I touch an element 
which didn't used to exist, instead of acting like it didn't exist, it 
creates it!  That's horrible!


Well, this used to work:

?php
$xmlstr = testitem1/item/test;
$xml = simplexml_load_string($xmlstr);
print_r($xml);

foreach ($xml-nonexist as $nonexist) {
   // do nothing
}
print_r($xml);
?

But now, the output of the print_r is different when I do it the second 
time because the foreach statement created nodes:


SimpleXMLElement Object
(
   [item] = 1
)
SimpleXMLElement Object
(
   [item] = 1
   [nonexist] = SimpleXMLElement Object
   (
   )
)

I think that's a bug and not a feature.  Why was this changed?

Dante

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml and serialize error

2006-04-30 Thread Richard Lynch
On Sat, April 29, 2006 8:30 pm, Anthony Ettinger wrote:
 Warning: var_dump() [function.var-dump]: Node no longer exists in
 Foo.php on line 78
 object(SimpleXMLElement)#86 (0) { } [title]=

 I turn an xml string into a simplexml object, and then ran serialize()
 on it before caching the output locally. When I read it back in and
 run unserialize() to do a dump, I get this error.

WILD GUESS!!!

Whatever class objects you had defined before you serialized the data,
are not defined when you unserialize the data.

You need to load all your class files in both serialize and
unserialize scripts -- The class definition is not stored in
serialized data, just the class 'data'

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simplexml and serialize error

2006-04-30 Thread Jochem Maas

Richard Lynch wrote:

On Sat, April 29, 2006 8:30 pm, Anthony Ettinger wrote:


Warning: var_dump() [function.var-dump]: Node no longer exists in
Foo.php on line 78
object(SimpleXMLElement)#86 (0) { } [title]=

I turn an xml string into a simplexml object, and then ran serialize()
on it before caching the output locally. When I read it back in and
run unserialize() to do a dump, I get this error.



WILD GUESS!!!

Whatever class objects you had defined before you serialized the data,
are not defined when you unserialize the data.

You need to load all your class files in both serialize and
unserialize scripts -- The class definition is not stored in
serialized data, just the class 'data'



A DIFFERENT WILD GUESS!!! :-)

I don't think thats the problem - rather I get the impression that
there are references  (and or resources) inside these SimpleXML objects
(e.g. the owning 'document') that cannot be serialized. I would suggest
caching the xml string and read that from disk (or where ever your storing
stuff) and creating an object from that whenever you need it. I don't believe 
that
you gain much from serializing an object (as compared to creating a new object) 
-
when you unserialize you have pretty much the same overhead as when creating an 
object
(I may be very wrong on this! - I do know that cloning an object is _much_ 
faster than
creating one for instance).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] simplexml and serialize error

2006-04-29 Thread Anthony Ettinger

Warning: var_dump() [function.var-dump]: Node no longer exists in
Foo.php on line 78
object(SimpleXMLElement)#86 (0) { } [title]=

I turn an xml string into a simplexml object, and then ran serialize()
on it before caching the output locally. When I read it back in and
run unserialize() to do a dump, I get this error.

--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout? [Resolved]

2006-04-11 Thread darren kirby
Just replying to my original post as means of a follow up. I have gone ahead 
and used Rasmus' code, he was correct in surmising I was only worried about 
an overloaded and slow responding site. It would be very atypical for the 
site to be down completely.

While the cache code was very interesting, I think it is a bit overkill 
considering the low amount of traffic my site receives. What I have done 
instead is to write the feed to a local file upon every update. I think it is 
more elegant to have an old feed than to have the terse Feed unavailable in 
the spot where the headlines should be.

I have tested by setting the timeout to '0' rather than yanking my ethernet 
cable and it seems to work well. I just don't have a suitable spare box to 
try the ethernet method, and setting the timeout to 0 seems to have the 
intended effect anyway.

Again, I just want to thank everybody involved for their time and effort, it 
is very much appreciated. 

Here is my function now, if anybody is interested:

function getFeed($url) {
$cache_version = $_SERVER['DOCUMENT_ROOT'] . /cache/ . basename($url);

$rfd = fopen($url, 'r');
stream_set_blocking($rfd,true);
stream_set_timeout($rfd, 5);  // 5-second timeout
$data = stream_get_contents($rfd);
$status = stream_get_meta_data($rfd);
fclose($rfd);
if ($status['timed_out']) {
$xml = simplexml_load_file($cache_version);
}
else {
$lfd = fopen($cache_version, 'w');
fwrite($lfd, $data);
fclose($lfd);
$xml = simplexml_load_string($data);
}

print ul\n;
foreach ($xml-channel-item as $item) {
$cleaned = str_replace(, amp;, $item-link);
print lia href='$cleaned'$item-title/a/li\n;
}
print /ul\n;
}

-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgpSQRnWoXs98.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread tedd

Here is an example Wez wrote years ago:


-snip code -

Years ago?

stream_socket_client() is php5.

How long ago did php5 launch?

tedd
--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Rasmus Lerdorf

tedd wrote:

Here is an example Wez wrote years ago:


-snip code -

Years ago?

stream_socket_client() is php5.

How long ago did php5 launch?


The first beta was in June 2003.  But the streams code was written well 
before that.


-Rasmus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread tedd

At 10:31 AM -0700 4/11/06, Rasmus Lerdorf wrote:

tedd wrote:

Here is an example Wez wrote years ago:


-snip code -

Years ago?

stream_socket_client() is php5.

How long ago did php5 launch?


The first beta was in June 2003.  But the streams code was written 
well before that.


-Rasmus


I'm running php 4 and stream_socket_client() isn't there. So, I 
figured that the example written years ago, must have been as recent 
as php5.


tedd
--

http://sperling.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Richard Lynch
On Mon, April 10, 2006 10:21 pm, Robert Cummings wrote:
 On Mon, 2006-04-10 at 23:11, Richard Lynch wrote:
 On Mon, April 10, 2006 9:59 pm, Rasmus Lerdorf wrote:
  Richard Lynch wrote:
 I've added a Note to 'fopen' so maybe others won't completely miss
 this feature and look as foolish as I do right now. :-)

 If it's anything like the helpful note I added about using copy(
 source,
 dest ) where dest accidentally points to source (due to linking),
 you'll
 get a nice retarded email like the following:

 ---

 You are receiving this email because your note posted
 to the online PHP manual has been removed by one of the editors.

I also have had what I still believe were actually quite useful
comments deleted :-(

And none of the reasoning in the stock form email applied, imho.

It's an awfully long stretch or a very thin line between these:
Feature Request: Documentation
User Contrbuted Note

I mean, the BEST User Contributed Notes probably qualify as Feature
Requests to improve the Docs, no?

Seems like those are the ones getting nuked, sometimes.

Oh well.

[shrug]

Better than the alternative of having a lot of utter [bleep] in the
User Contributed sections, I guess.

Still, maybe an appeal or a reader-voting system would make more
sense than a PHP Dev/Doc Team member copy-editing every note...

Obviously you'd still want a Doc Team member stepping in at some point
and just nuking anything blatantly wrong no matter how popular...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Richard Lynch
On Mon, April 10, 2006 10:24 pm, Rasmus Lerdorf wrote:
 You could volunteer to help maintain the user notes.

I've just spent five/ten minutes with Google and php.net trying to
find the best way to volunteer to do just that...

Admittedly not a LOT of effort, but...

Where do I start?

I do have one reservation, though...

Last time I tried to do something like this, I ended up having a hard
drive with what felt like Gigabytes of PHP Doc source code from CVS
(which was an adventure in itself back then) and then had to attempt
to run software that chewed up so much RAM/CPU and never managed to
actually get useful output before crashing from lack of resources.

Granted, this was a decade ago, and my hardware was pretty crappy at
the time...  Not that I've got much better gear now, mind you. :-)

I'm guessing though that these days, it's just a web form somewhere. 
I can handle that. :-)

Though it might finally be time for me to take another whack at PHP
CVS development and see if I can't contribute even more...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-11 Thread Rasmus Lerdorf

Richard Lynch wrote:

On Mon, April 10, 2006 10:24 pm, Rasmus Lerdorf wrote:

You could volunteer to help maintain the user notes.


I've just spent five/ten minutes with Google and php.net trying to
find the best way to volunteer to do just that...

Admittedly not a LOT of effort, but...

Where do I start?


Start by reading http://php.net/dochowto
Specifically chapter 11 -

  http://doc.php.net/php/dochowto/chapter-user-notes.php

That should everyone here some insight into the user notes process.


I do have one reservation, though...

Last time I tried to do something like this, I ended up having a hard
drive with what felt like Gigabytes of PHP Doc source code from CVS
(which was an adventure in itself back then) and then had to attempt
to run software that chewed up so much RAM/CPU and never managed to
actually get useful output before crashing from lack of resources.

Granted, this was a decade ago, and my hardware was pretty crappy at
the time...  Not that I've got much better gear now, mind you. :-)

I'm guessing though that these days, it's just a web form somewhere. 
I can handle that. :-)


For just auditing notes, you can do it via a web form, yes.  And now 
with livedocs, you can get instant feedback if you want to progress to 
actually work on the main manual pages themselves.  The above howto


-Rasmus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread darren kirby
Hello all,

My website uses simpleXML to print the headlines from a few different RSS 
feeds. The problem is that sometimes the remote feed is unavailable if there 
are problems with the remote site, and the result is that I must wait for 30 
seconds or so until the HTTP timeout occurs, delaying the rendering of my 
site.

So far, I have moved the code that grabs the RSS feeds to the bottom of my 
page, so that the main page content is rendered first, but this is only a 
partial solution.

Is there a way to give the simplexml_load_file() a 5 second timeout before 
giving up and moving on? 

Here is my function:

function getFeed($remote) {
if (!$xml = simplexml_load_file($remote)) {
print Feed unavailable;
return;
}
print ul\n;
foreach ($xml-channel-item as $item) {
$cleaned = str_replace(, amp;, $item-link); 
print lia href='$cleaned'$item-title/a/li\n;
}
print /ul\n;
}

PHP 5.1.2 on Linux.
thanks,
-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgpMd5exSvq6N.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Robert Cummings
On Mon, 2006-04-10 at 15:25, darren kirby wrote:
 Hello all,
 
 My website uses simpleXML to print the headlines from a few different RSS 
 feeds. The problem is that sometimes the remote feed is unavailable if there 
 are problems with the remote site, and the result is that I must wait for 30 
 seconds or so until the HTTP timeout occurs, delaying the rendering of my 
 site.
 
 So far, I have moved the code that grabs the RSS feeds to the bottom of my 
 page, so that the main page content is rendered first, but this is only a 
 partial solution.
 
 Is there a way to give the simplexml_load_file() a 5 second timeout before 
 giving up and moving on? 
 
 Here is my function:
 
 function getFeed($remote) {
 if (!$xml = simplexml_load_file($remote)) {
 print Feed unavailable;
 return;
 }
 print ul\n;
 foreach ($xml-channel-item as $item) {
 $cleaned = str_replace(, amp;, $item-link); 
 print lia href='$cleaned'$item-title/a/li\n;
 }
 print /ul\n;
 }

Why do you do this on every request? Why not have a cron job retrieve an
update every 20 minutes or whatnot and stuff it into a database table
for your page to access? Then if the cron fails to retrieve the feed it
can just leave the table as is, and your visitors can happily view
slightly outdated feeds? Additionally this will be so much faster that
your users might even hang around on your site :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread darren kirby
quoth the Robert Cummings:

 Why do you do this on every request? Why not have a cron job retrieve an
 update every 20 minutes or whatnot and stuff it into a database table
 for your page to access? Then if the cron fails to retrieve the feed it
 can just leave the table as is, and your visitors can happily view
 slightly outdated feeds? Additionally this will be so much faster that
 your users might even hang around on your site :)

This is a very interesting idea, but I am not sure if it is suitable for me at 
this point. First of all, one feed in particular can change in a matter of 
seconds, and I do want it to be as up to date as possible. Secondly, this is 
just for my personal site which is very low traffic, and it is not 
inconceivable that getting the feed every 20 minutes by cron would be _more_ 
taxing on the network than simply grabbing it per request...

And to be fair, when everything is working as it should the feeds are 
retrieved in a matter of seconds, and I don't think it is annoying my users 
at all. It is the 0.5% of requests when the remote site is overloaded (or 
just plain down) that I want to provision for here.

I do like this idea of caching the feed though. I think in my situation 
though, rather than prefetching the feed at regular intervals it may be 
better to cache the most recent request, and check the age of the cache when 
the next request comes. This way, I would not be needlessly updating it for 
those times when the page with my feeds goes for a few hours without a 
request.

Of course, this still wouldn't solve my original problem.

 Cheers,
 Rob.
 --

Thanks for your insight,
-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgp80qbla946k.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Robert Cummings
On Mon, 2006-04-10 at 17:46, darren kirby wrote:
 quoth the Robert Cummings:
 
  Why do you do this on every request? Why not have a cron job retrieve an
  update every 20 minutes or whatnot and stuff it into a database table
  for your page to access? Then if the cron fails to retrieve the feed it
  can just leave the table as is, and your visitors can happily view
  slightly outdated feeds? Additionally this will be so much faster that
  your users might even hang around on your site :)
 
 This is a very interesting idea, but I am not sure if it is suitable for me 
 at 
 this point. First of all, one feed in particular can change in a matter of 
 seconds, and I do want it to be as up to date as possible. Secondly, this is 
 just for my personal site which is very low traffic, and it is not 
 inconceivable that getting the feed every 20 minutes by cron would be _more_ 
 taxing on the network than simply grabbing it per request...
 
 And to be fair, when everything is working as it should the feeds are 
 retrieved in a matter of seconds, and I don't think it is annoying my users 
 at all. It is the 0.5% of requests when the remote site is overloaded (or 
 just plain down) that I want to provision for here.
 
 I do like this idea of caching the feed though. I think in my situation 
 though, rather than prefetching the feed at regular intervals it may be 
 better to cache the most recent request, and check the age of the cache when 
 the next request comes. This way, I would not be needlessly updating it for 
 those times when the page with my feeds goes for a few hours without a 
 request.
 
 Of course, this still wouldn't solve my original problem.

Well personal websites break all the rules. There's nobody to answer to
but yourself :)

Looks like simplexml neglected to offer a timeout option. You would
probably be better off using curl to retrieve the content, then using
simplexml_load_string(). Curl does allow you to assign a timeout.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread darren kirby
quoth the Robert Cummings:
 On Mon, 2006-04-10 at 17:46, darren kirby wrote:
  quoth the Robert Cummings:
   Why do you do this on every request? Why not have a cron job retrieve
   an update every 20 minutes or whatnot and stuff it into a database
   table for your page to access? Then if the cron fails to retrieve the
   feed it can just leave the table as is, and your visitors can happily
   view slightly outdated feeds? Additionally this will be so much faster
   that your users might even hang around on your site :)
 
  This is a very interesting idea, but I am not sure if it is suitable for
  me at this point. First of all, one feed in particular can change in a
  matter of seconds, and I do want it to be as up to date as possible.
  Secondly, this is just for my personal site which is very low traffic,
  and it is not inconceivable that getting the feed every 20 minutes by
  cron would be _more_ taxing on the network than simply grabbing it per
  request...
 
  And to be fair, when everything is working as it should the feeds are
  retrieved in a matter of seconds, and I don't think it is annoying my
  users at all. It is the 0.5% of requests when the remote site is
  overloaded (or just plain down) that I want to provision for here.
 
  I do like this idea of caching the feed though. I think in my situation
  though, rather than prefetching the feed at regular intervals it may be
  better to cache the most recent request, and check the age of the cache
  when the next request comes. This way, I would not be needlessly updating
  it for those times when the page with my feeds goes for a few hours
  without a request.
 
  Of course, this still wouldn't solve my original problem.

 Well personal websites break all the rules. There's nobody to answer to
 but yourself :)

 Looks like simplexml neglected to offer a timeout option. You would
 probably be better off using curl to retrieve the content, then using
 simplexml_load_string(). Curl does allow you to assign a timeout.

That's the ticket! Thanks a lot for your help.

 Cheers,
 Rob.

-d

 ..

 | InterJinn Application Framework - http://www.interjinn.com |
 |
 ::
 :
 | An application and templating framework for PHP. Boasting  |
 | a powerful, scalable system for accessing system services  |
 | such as forms, properties, sessions, and caches. InterJinn |
 | also provides an extremely flexible architecture for   |
 | creating re-usable components quickly and easily.  |

 `'

-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgp1pVIKLSoO2.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Martin Alterisio
Maybe you can read the contents of the feeds using fsockopen() and
stream_set_timeout() to adjust the timeout, or stream_set_blocking()
to read it asynchronously, and then load the xml with
simplexml_load_string().

PS: I forgot to reply to all and mention you'll have to send the GET
http command and headers, check the php manual for examples.

2006/4/10, darren kirby [EMAIL PROTECTED]:
 Hello all,

 My website uses simpleXML to print the headlines from a few different RSS
 feeds. The problem is that sometimes the remote feed is unavailable if there
 are problems with the remote site, and the result is that I must wait for 30
 seconds or so until the HTTP timeout occurs, delaying the rendering of my
 site.

 So far, I have moved the code that grabs the RSS feeds to the bottom of my
 page, so that the main page content is rendered first, but this is only a
 partial solution.

 Is there a way to give the simplexml_load_file() a 5 second timeout before
 giving up and moving on?

 Here is my function:

 function getFeed($remote) {
 if (!$xml = simplexml_load_file($remote)) {
 print Feed unavailable;
 return;
 }
 print ul\n;
 foreach ($xml-channel-item as $item) {
 $cleaned = str_replace(, amp;, $item-link);
 print lia href='$cleaned'$item-title/a/li\n;
 }
 print /ul\n;
 }

 PHP 5.1.2 on Linux.
 thanks,
 -d
 --
 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
 ...the number of UNIX installations has grown to 10, with more expected...
 - Dennis Ritchie and Ken Thompson, June 1972




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread darren kirby

quoth the Martin Alterisio:
 Maybe you can read the contents of the feeds using fsockopen() and
 stream_set_timeout() to adjust the timeout, or stream_set_blocking()
 to read it asynchronously, and then load the xml with
 simplexml_load_string().

Hello, and thanks for the response,

As Robert Cummings suggested above, the easy solution is to use curl, which 
does offer a timeout option, and then feed it to simplexml_load_string().

I am writing some code now...

Thanks, and have a good one,
-d

-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgpn7Z5Ag4G6c.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Rasmus Lerdorf

Martin Alterisio wrote:

Maybe you can read the contents of the feeds using fsockopen() and
stream_set_timeout() to adjust the timeout, or stream_set_blocking()
to read it asynchronously, and then load the xml with
simplexml_load_string().

PS: I forgot to reply to all and mention you'll have to send the GET
http command and headers, check the php manual for examples.


You can just use fopen() to avoid all that.

eg.

$fd = fopen($url);
stream_set_blocking($fd,true);
stream_set_timeout($fd, 5);  // 5-second timeout
$data = stream_get_contents($fd);
$status = stream_get_meta_data($fd);
if($status['timed_out']) echo Time out;
else {
  $xml = simplexml_load_string($data);
}

As for your caching, make sure you create the cache file atomically.  So 
how about this:


function request_cache($url, $dest_file, $ctimeout=60, $rtimeout=5) {
  if(!file_exists($dest_file) || filemtime($dest_file)  
(time()-$ctimeout)) {

$stream = fopen($url,'r');
stream_set_blocking($stream,true);
stream_set_timeout($stream, $rtimeout);
$tmpf = tempnam('/tmp','YWS');
file_put_contents($tmpf, $stream);
fclose($stream);
rename($tmpf, $dest_file);
  }
}

That takes the url to your feed, a destination file to cache to, a cache 
timeout (as in, fetch from the feed if the cache is older than 60 
seconds) and finally the request timeout.


Note the file_put_contents of the stream straight to disk, so you don't 
ever suck the file into memory.  You can then use a SAX parser like 
xmlreader on it and your memory usage will be minimal.  You will need 
PHP 5.1.x for this to work.


You could also use apc_store/fetch and skip the disk copy altogether.

(untested and typed up during a long boring meeting, so play with it a bit)

-Rasmus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Richard Lynch
On Mon, April 10, 2006 4:46 pm, darren kirby wrote:
 quoth the Robert Cummings:

 Why do you do this on every request? Why not have a cron job
 retrieve an
 update every 20 minutes or whatnot and stuff it into a database
 table
 for your page to access? Then if the cron fails to retrieve the feed
 it
 can just leave the table as is, and your visitors can happily view
 slightly outdated feeds? Additionally this will be so much faster
 that
 your users might even hang around on your site :)

 This is a very interesting idea, but I am not sure if it is suitable
 for me at
 this point. First of all, one feed in particular can change in a
 matter of
 seconds, and I do want it to be as up to date as possible. Secondly,
 this is
 just for my personal site which is very low traffic, and it is not
 inconceivable that getting the feed every 20 minutes by cron would be
 _more_
 taxing on the network than simply grabbing it per request...

Perhaps, then, you should:
maintain a list of URLs and acceptable age of feed.
Attempt to snag the new content upon visit, if the content is old
Show the old content if the feed takes longer than X seconds.

You'll STILL need a timeout, which, unfortunately, means you are stuck
rolling your own solution with http://php.net/fsockopen because all
the simple solutions pretty much suck in terms of network timeout.
:-(

It would be REALLY NIFTY if fopen and friends which understand all
those protocols of HTTP FTP HTTPS and so on, allowed one to set a
timeout for URLs, but they don't and nobody with the skills to change
that (not me) seems even mildly interested. :-( :-( :-(

Since I've already written a class that does something like what you
want, or maybe even exactly what you want, I might as well just
provide the source, eh?

http://l-i-e.com/FeedMulti/FeedMulti.phps

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Richard Lynch
On Mon, April 10, 2006 6:17 pm, Rasmus Lerdorf wrote:
 Martin Alterisio wrote:
 Maybe you can read the contents of the feeds using fsockopen() and
 stream_set_timeout() to adjust the timeout, or stream_set_blocking()
 to read it asynchronously, and then load the xml with
 simplexml_load_string().

 PS: I forgot to reply to all and mention you'll have to send the GET
 http command and headers, check the php manual for examples.

 You can just use fopen() to avoid all that.

No, he can't.

Sorry, Rasmus. :-)

If the URL is not working at the time of fopen() then you'll sit there
spinning your wheels waiting for fopen() itself to timeout, before you
ever GET a valid file handle to which one can apply stream_set_timeout
and/or stream_set_blocking.

That can take MUCH too long.

So you're STUCK with fsockopen, which DOES take a timeout parameter
for OPENING the socket, as well as giving one a stream to which
stream_set_blocking and stream_set_timeout can be applied.

But then you are stuck re-inventing the damn wheel with any protocol
you'd like to support like GET/POST, HTTPS (ugh!), FTP and so on.

All of which is buried in the guts of the Truly Nifty fopen,
file_get_contents, and so forth, but is utterly useless if you care at
all about timing out in a reasonably-responsive application.

So you have do all the junk to send things like:
GET / HTTP/1.0
Host: example.com
yourself, and God help you if you want to support HTTPS.

Actually, curl MAY be the better solution -- but my boss doesn't have
curl installed, so I was screwed anyway...

This is why I (and others) have put in a Feature Request to get
fopen() and friends to have some kind of programmatically changable
timeout setting.  Said Feature Requests invariably get marked Bogus
and then commented with something like the non-solution above. :-)

Oh well.

It *can* be done; You just have to type WAY too much junk to do
something very simple and very commonly needed.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread darren kirby
quoth the Richard Lynch:
 Perhaps, then, you should:
 maintain a list of URLs and acceptable age of feed.
 Attempt to snag the new content upon visit, if the content is old
 Show the old content if the feed takes longer than X seconds.

I really do like this idea, as I would rather use an old feed than just print 
Feed unavailable as I have it now.

 You'll STILL need a timeout, which, unfortunately, means you are stuck
 rolling your own solution with http://php.net/fsockopen because all
 the simple solutions pretty much suck in terms of network timeout.

 :-(

 It would be REALLY NIFTY if fopen and friends which understand all
 those protocols of HTTP FTP HTTPS and so on, allowed one to set a
 timeout for URLs, but they don't and nobody with the skills to change
 that (not me) seems even mildly interested. :-( :-( :-(

I am interested, but I don't have the skills either...

 Since I've already written a class that does something like what you
 want, or maybe even exactly what you want, I might as well just
 provide the source, eh?

 http://l-i-e.com/FeedMulti/FeedMulti.phps

Thanks for that, it looks like interesting code, if not a little over my head. 
I am just a duffer here. I will certainly play with it some more. As for 
curl, I realized I didn't add curl support myself, so I am rebuilding PHP 
now... 

When I do get something figured out I will post results here. Problem is, with 
either method I need to find a feed that is slow to test with. If I test it 
with a bunk url it will just 404 immediately right? Is there a way to 
simulate a slow connection?

 --
 Like Music?
 http://l-i-e.com/artists.htm

Thanks a lot for the help, everybody!
-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
...the number of UNIX installations has grown to 10, with more expected...
- Dennis Ritchie and Ken Thompson, June 1972


pgp8eJbTMrXbb.pgp
Description: PGP signature


Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Robert Cummings
On Mon, 2006-04-10 at 20:52, darren kirby wrote:
 quoth the Richard Lynch:
  Perhaps, then, you should:
  maintain a list of URLs and acceptable age of feed.
  Attempt to snag the new content upon visit, if the content is old
  Show the old content if the feed takes longer than X seconds.
 
 I really do like this idea, as I would rather use an old feed than just print 
 Feed unavailable as I have it now.
 
  You'll STILL need a timeout, which, unfortunately, means you are stuck
  rolling your own solution with http://php.net/fsockopen because all
  the simple solutions pretty much suck in terms of network timeout.
 
  :-(
 
  It would be REALLY NIFTY if fopen and friends which understand all
  those protocols of HTTP FTP HTTPS and so on, allowed one to set a
  timeout for URLs, but they don't and nobody with the skills to change
  that (not me) seems even mildly interested. :-( :-( :-(
 
 I am interested, but I don't have the skills either...
 
  Since I've already written a class that does something like what you
  want, or maybe even exactly what you want, I might as well just
  provide the source, eh?
 
  http://l-i-e.com/FeedMulti/FeedMulti.phps
 
 Thanks for that, it looks like interesting code, if not a little over my 
 head. 
 I am just a duffer here. I will certainly play with it some more. As for 
 curl, I realized I didn't add curl support myself, so I am rebuilding PHP 
 now... 
 
 When I do get something figured out I will post results here. Problem is, 
 with 
 either method I need to find a feed that is slow to test with. If I test it 
 with a bunk url it will just 404 immediately right? Is there a way to 
 simulate a slow connection?

For sure ;) Pull your ethernet cable out. Doesn't get much slower :D

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Richard Lynch
 When I do get something figured out I will post results here. Problem
 is, with
 either method I need to find a feed that is slow to test with. If I
 test it
 with a bunk url it will just 404 immediately right? Is there a way to
 simulate a slow connection?

I dunno about similating a slow connection, but you can write a very
slow server... :-)

my_slow_rss_feed.php
?php
  $data = 'nameDarren Kirby/name';
  sleep(10);
  for ($i = 0; $i  strlen($data); $i++){
echo $data[$i];
flush();
sleep(1);
  }
?

Of course, that doesn't simulate the slow connection part of it...

If you have 2 machines, you can unplug the network cable, start your
script, then plug the cable in after 5 seconds.

That's gonna make it pretty slow to connect, almost for sure. :-)

If anybody is goofy enough to complain about the performance of
strlen() in the for(...) statement, you're clearly not paying
attention. :-) :-) :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] simpleXML - simplexml_load_file() timeout?

2006-04-10 Thread Martin Alterisio \El Hombre Gris\
Maybe it's too late to say this, but if your real problem is that you 
don't want the function reading
the rss feed to block the rest of your page, you can always put the 
output of the reading of the feed

on a separate page, and include this through an iframe.

darren kirby wrote:


Hello all,

My website uses simpleXML to print the headlines from a few different RSS 
feeds. The problem is that sometimes the remote feed is unavailable if there 
are problems with the remote site, and the result is that I must wait for 30 
seconds or so until the HTTP timeout occurs, delaying the rendering of my 
site.


So far, I have moved the code that grabs the RSS feeds to the bottom of my 
page, so that the main page content is rendered first, but this is only a 
partial solution.


Is there a way to give the simplexml_load_file() a 5 second timeout before 
giving up and moving on? 


Here is my function:

function getFeed($remote) {
   if (!$xml = simplexml_load_file($remote)) {
   print Feed unavailable;
   return;
   }
   print ul\n;
   foreach ($xml-channel-item as $item) {
   $cleaned = str_replace(, amp;, $item-link); 
   print lia href='$cleaned'$item-title/a/li\n;

   }
   print /ul\n;
}

PHP 5.1.2 on Linux.
thanks,
-d
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   >