omnipix Posted November 9, 2013 Report Share Posted November 9, 2013 Sveiki, Gribētu uzzināt kā ar PHP un SimpleXML validēt XML faila lauku kurš ir tukš? mans XML: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <CD_Albums> <cd-id>lg656363</cd-id> <cd-name>Lacim pofig</cd-name> <cd-author>Bomārs</cd-author> <cd-price>2.64LS</cd-price> </CD_Albums> <CD_Albums> <cd-id>bvbvbvbvbvbv</cd-id> <cd-name>Kurmis</cd-name> <cd-author>Zilais Varis</cd-author> <cd-price>6.73LS</cd-price> </CD_Albums> <CD_Albums> <cd-id>74646464664664</cd-id> <cd-name>Bebri ziemā krosu skrien</cd-name> <cd-author>Rižiks</cd-author> <cd-price></cd-price> </CD_Albums></root> Kā redzams pēdejam ierakstam nav cena (empty value). Kā lai ar PHP es tam tieku klāt un attiecīgi ar if () {}esle{} to neparādu vai ko citu ar to izdaru. Ir kādas idejas? Quote Link to comment Share on other sites More sharing options...
gurkjis Posted November 9, 2013 Report Share Posted November 9, 2013 (edited) šitā: $xml = simplexml_load_file('test.xml'); foreach ($xml->CD_Albums as $album) { if (empty($album->{'cd-price'})) { // tukšs: darīt kaut ko echo 'empty: '.$album->{'cd-name'}.'<br/>'; } } $album->cd-price nevar lietot, jo lauka nosaukumā ir mīnus zīme, tāpēc tiek lietots $album->{'cd-price'} Edited November 9, 2013 by gurkjis Quote Link to comment Share on other sites More sharing options...
omnipix Posted November 9, 2013 Author Report Share Posted November 9, 2013 šitā: $xml = simplexml_load_file('test.xml'); foreach ($xml->CD_Albums as $album) { if (empty($album->{'cd-price'})) { // tukšs: darīt kaut ko echo 'empty: '.$album->{'cd-name'}.'<br/>'; } } $album->cd-price nevar lietot, jo lauka nosaukumā ir mīnus zīme, tāpēc tiek lietots $album->{'cd-price'} Paldies, viss aizgāja tagad! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.