Stripping blank XML tags from PHP generated XML files? -
i have generated xml file database using php dom functions. save file using dom->save("feed.xml").
the problem i'm facing of rows in database have empty feilds, resulting in type of output -
<summary/>  as summary field empty.
is possible remove these tags without affecting other nodes? reason want remove them xml fed app , don't want take in blank fields inconsistent.
does know of way acheive desire?
thanks.
you use xpath() select empty nodes , delete them:
example xml:
<root>     <test/>     <test></test>     <test>         <name>michi</name>         <name/>     </test>     </root> php:
$xml = simplexml_load_string($x); // assume xml in $x  // select node @ position in tree has no children , no text // store them in array $results $results = $xml->xpath("//*[not(node())]");  // iterate , delete foreach ($results $r) unset($r[0]);  // display new xml echo $xml->asxml();  output:
<?xml version="1.0"?> <root>     <test>         <name>michi</name>         </test>     </root> see working: https://eval.in/236071
Comments
Post a Comment