xml - Why does PHP SimpleXML children() returns null for empty tag? -


we have following sample xml:

<xml>     <call>         <branchid>2</branchid>         <item_main_display>1</item_main_display>         <workstation_id>1</workstation_id>         <formatted_ticket_number>203</formatted_ticket_number>         <queue_letter></queue_letter>         <service_id>17</service_id>         <service_name>konsultanti queue</service_name>         <isflashing>false</isflashing>         <workstation_name>servicepoint_d924</workstation_name>         <calltime>1442583923157</calltime>         <timestamp>1442583923</timestamp>         <eventtime>2015-09-18t17:45:23.114+0400</eventtime>     </call> </xml> 

using followin php code try access xml nodes;

$xml=simplexml_load_file("sample.xml");  $xmlstr=""; $xmlstr.="<xml>";  foreach($xml->children() $child1) {     $xmlstr.="<". $child1->getname().">";     foreach($child1->children() $child2){          $xmlstr.="<". $child2->getname() .">". $child2 ."</". $child2->getname() .">";     }      $xmlstr.="</". $child1->getname().">"; } $xmlstr.="</xml>"; 

this code works fine, except: tag

<queue_letter></queue_letter>     

for tag $child1->children() returns null; if enter space between tags

<queue_letter>     </queue_letter>  

or newline, or other character, tag returned.

is normal behaviour? how can return child tags contain no character?

thank you.

if have space between tags, tag isn't empty - has 1 text node it's child.

<queue_letter></queue_letter> same <queue_letter /> , tag has no children, return null


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -