raaks Posted November 25, 2011 Share Posted November 25, 2011 I have come across couple of similar answers for my question in this form, but could not solve my exact problem. Therefore I am posting this here: I have an xml file as shown below: <?xml version="1.0" encoding="ISO-8859-1"?> <document> <user> <user_id>0121</user_id> <name>Tim</name> <file>0121.file</file> </user> <user> <user_id>0178</user_id> <name>Henry</name> <file>0178.file</file> </user> <user> <user_id>0786</user_id> <name>Martin</name> <file>0786.file</file> </user> <user> <user_id>1239</user_id> <name>Jan</name> <file>1239.file</file> </user> </document> I ask the user to input his user_id and post this user_id and perform a check on the entire xml file to check whether the entered user_id exists in the xml file or not. If exists then I go further if not echo a error message. Can anybody pull me out of this? Thanks Link to comment https://forums.phpfreaks.com/topic/251784-checking-whether-the-searching-attribute-exists-in-a-xml-file-using-php/ Share on other sites More sharing options...
btellez Posted November 25, 2011 Share Posted November 25, 2011 What have you tried? Are you using simplexml_load_file (or simplexml_load_string) Here's an example from php.net // The file test.xml contains an XML document with a root element // and at least an element /[root]/title. if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Failed to open test.xml.'); } outputs: SimpleXMLElement Object ( [title] => Example Title ) from an xml file that had xml along these lines: <?xml version="1.0" encoding="UTF-8"?> <docroot> <title>Example Title</title> </docroot> Link to comment https://forums.phpfreaks.com/topic/251784-checking-whether-the-searching-attribute-exists-in-a-xml-file-using-php/#findComment-1291179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.