oquidave

xmlparse

May 19th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. $xml = <<<EOD
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <SENDBATCH user='username' password='password' application='50' reply='EMAIL:[email protected]'>
  4. This is a test
  5. <SMSLIST>
  6. <SMS_SEND to='256791040262' uid='1'/>
  7. <SMS_SEND to='256754819815' uid='2'/>
  8. </SMSLIST>
  9. <SMSGROUP>
  10. <SMS_SEND to='256791234567' uid='3'/>
  11. <SMS_SEND to='256754819814' uid='4'/>
  12. </SMSGROUP>
  13. </SENDBATCH>
  14. EOD;
  15.  
  16. $xmlObject = new SimpleXMLElement($xml);
  17. //root name
  18. $rootnode = $xmlObject->getName();
  19. //children count
  20. $children_no = count($xmlObject->children());
  21. //get the message
  22. $msg = $xmlObject->SENDBATCH;
  23. //get attributes of the root node
  24. foreach ($xmlObject->attributes() as $key=>$value) {
  25.  
  26. switch ($key) {
  27. case 'user':
  28. $user = $value[0];
  29. break;
  30. case 'password':
  31. $password = $value[0];
  32. break;
  33. case 'application':
  34. $application = $value[0];
  35. break;
  36. case 'reply':
  37. $reply = $value[0];
  38. break;
  39. default:
  40. ;
  41. break;
  42. }//close switch
  43. }
Advertisement
Add Comment
Please, Sign In to add comment