jug Posted January 23, 2008 Share Posted January 23, 2008 Hi. I have got a xml file (xmlphoto.xml). I need to query the file to find out which row contains title="green", and then remove that row. Im pretty sure i need the row index to remove the row. Im new to xml so any basic help would be much apprecaiated. <gallery> <image title="blue"> <image title="green"> <image title="pink"> </gallery> thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/ Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 Starting with valid XML would be a help. Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446805 Share on other sites More sharing options...
jug Posted January 23, 2008 Author Share Posted January 23, 2008 I know what you mean but i am working with a flash developer who says he needs the syntax to stay like it is. Its the PHP and DOM i need help with to query it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446810 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 Sorry, but I can't help you to process an XML file that isn't in XML format and won't even get through the parsing stage. Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446812 Share on other sites More sharing options...
jug Posted January 23, 2008 Author Share Posted January 23, 2008 Yeh i see where youre coming from. Could you guide me in using a valid xml file and ill see where that can help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446816 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 http://www.w3schools.com/xml/xml_whatis.asp http://us.php.net/manual/en/ref.simplexml.php Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446820 Share on other sites More sharing options...
jug Posted January 23, 2008 Author Share Posted January 23, 2008 thanks for the quick replies. So is it simply not possible to do anything with the xml i gave? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446822 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 All you gave was some text with a few tags, not valid XML. If that is representative of your xml file then your developer should be having problems with it too. Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446830 Share on other sites More sharing options...
pdkv2 Posted January 23, 2008 Share Posted January 23, 2008 <php $xmlobj = simplexml_load_file("filename.xml"); if($xmlobj == false){ $flag = false; echo $message = "Error: XML file cannot be loaded"; }else{ foreach($xmlobj as $obj){ if($obj['title']=="green"){ $obj['title']=""; } } echo $xmlobj->asXML(); } ?> Use this code snippet Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446837 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 unfortunately <?php $str = '<gallery> <image title="blue"> <image title="green"> <image title="pink"> </gallery>'; $xmlobj = simplexml_load_string($str); if($xmlobj == false){ $flag = false; echo $message = "Error: XML file cannot be loaded"; }else{ foreach($xmlobj as $obj){ if($obj['title']=="green"){ $obj['title']=""; } } echo $xmlobj->asXML(); } ?> gives --> Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Opening and ending tag mismatch: image line 4 and gallery in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag image line 3 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag image line 2 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag gallery line 1 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Error: XML file cannot be loaded Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446841 Share on other sites More sharing options...
pdkv2 Posted January 23, 2008 Share Posted January 23, 2008 unfortunately <?php $str = '<gallery> <image title="blue"> <image title="green"> <image title="pink"> </gallery>'; $xmlobj = simplexml_load_string($str); if($xmlobj == false){ $flag = false; echo $message = "Error: XML file cannot be loaded"; }else{ foreach($xmlobj as $obj){ if($obj['title']=="green"){ $obj['title']=""; } } echo $xmlobj->asXML(); } ?> gives --> Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Opening and ending tag mismatch: image line 4 and gallery in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag image line 3 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag image line 2 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 5: parser error : Premature end of data in tag gallery line 1 in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: </gallery> in C:\Inetpub\wwwroot\test\noname7.php on line 11 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in C:\Inetpub\wwwroot\test\noname7.php on line 11 Error: XML file cannot be loaded Use this as the XML is not well formed in above <?php $str = '<?xml version=\"1.0\" encoding=\"UTF-8\"?> <gallery> <image title="blue"/> <image title="green"/> <image title="pink"/> </gallery>'; $xmlobj = simplexml_load_string($str); if($xmlobj == false){ $flag = false; echo $message = "Error: XML file cannot be loaded"; }else{ foreach($xmlobj as $obj){ if($obj['title']=="green"){ $obj['title']=""; } } echo $xmlobj->asXML(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446844 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 I'm well aware of that All you gave was some text with a few tags, not valid XML. If that is representative of your xml file then your developer should be having problems with it too. Quote Link to comment https://forums.phpfreaks.com/topic/87350-query-php-with-xml-probably-simple-to-solve/#findComment-446845 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.