php - XML XPath check if node exist... then -


i have complex xml exported db. hakre's answer post can convert xml - php - array wished.

the conversion of xml array perfect, there's still issue fix.

the part of xml i'm working on following:

<comma>     <num><num>     <alinea>lorem ipsum...</alinea> </comma> <comma>     <num></num>     <corpo>dolor sit amet...</corpo> </comma> 

don't ask me why, may see excerpt child of comma alinea , child corpo.

now can convert above excerpt of xml array using hakre's code:

<commi expr="a:comma">     <num_alinea expr="concat(a:num, a:alinea)"/> </commi> 

but alinea tag had change into:

<commi expr="a:comma">       <num_alinea expr="string(a:alinea)"/>     <num_corpo expr="string(a:corpo)"/> </commi> 

the above code work array generated output this:

array     (         [num_alinea] => lorem ipsum...         [num_corpo] =>     ) 

or

array     (         [num_alinea] =>         [num_corpo] => dolor sit amet...     ) 

where num_alinea or num_corpo empty or not depending on existence of tags alinea or corpo in xml.

can add conditional statement xml expr above? suppose have use this:

<text expr="boolean(a:alinea)"/> 

but don't know how instruct xpath say:

"if exists node [alinea] content, if exist node [corpo] content". 

i'm not sure about origin of expressions in expr tag. these xpath expressions? can find more them? there manual/tutorial or list of statements learn on?


Comments