Skip to main content
minor typo fix.
Source Link
Jeremy French
  • 12.3k
  • 6
  • 48
  • 73

I just gave your test a shot because i was curious and I foudfound that it does actuallactually produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $found[0] if you are not printing/echoing it directly.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue I suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable.

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear.

I just gave your test a shot because i was curious and I foud that it does actuall produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $found[0] if you are not printing/echoing it directly.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue I suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable.

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear.

I just gave your test a shot because i was curious and I found that it does actually produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $found[0] if you are not printing/echoing it directly.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue I suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable.

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear.

added 4 characters in body
Source Link
hakre
  • 199.8k
  • 55
  • 454
  • 865

I just gave your test a shot because i was curious and I foud that it does actuall produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElementSimpleXmlElement attribute nodes are represented. So you can use this as (string) $fruits[0]$found[0] if you arent directlyare not printing/echoing it directly.

Of course if your depending on the value remaining a SimpleXMLElementSimpleXMLElement then that could be an issue iI suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable...

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocumentDOMDocument. You code will get more verbose, but the implementation is more clear cut.

I just gave your test a shot because i was curious and I foud that it does actuall produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $fruits[0] if you arent directly printing/echoing.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue i suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable...

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear cut.

I just gave your test a shot because i was curious and I foud that it does actuall produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $found[0] if you are not printing/echoing it directly.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue I suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable.

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear.

Source Link
prodigitalson
  • 60.6k
  • 10
  • 106
  • 118

I just gave your test a shot because i was curious and I foud that it does actuall produce the string value yellow when converted to string.

$fruits = simplexml_load_string( '<fruits> <kiwi color="green" texture="hairy"/> <banana color="yellow" texture="waxy"/> </fruits>'); $found = $fruits->xpath('//banana/@color'); echo $found[0]; 

It would seem this is just how SimpleXmlElement attribute nodes are represented. So you can use this as (string) $fruits[0] if you arent directly printing/echoing.

Of course if your depending on the value remaining a SimpleXMLElement then that could be an issue i suppose. But i would think just remembering to cast as string when you go to use the node later would still be doable...

IF you really need a detailed interface for Nodes that supports an Attribute as a node then you may want to just switch to DOMDocument. You code will get more verbose, but the implementation is more clear cut.