code_junkie

PHP simplexml problem

Nov 11th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?xml version="1.0" ?>
  2. <course xml:lang="nl">
  3. <body>
  4. <item id="787900813228567" view="12000" title="0x|Beschrijving" engtitle="0x|Description"><![CDATA[Dit college leert studenten hoe ze een onderzoek kunn$
  5. <item id="5453116633894965" view="12000" title="0x|Onderwijsvorm" engtitle="0x|Method of instruction"><![CDATA[instructiecollege]]></item>
  6. <item id="7433550075448316" view="12000" title="0x|Toetsing" engtitle="0x|Examination"><![CDATA[Opdrachten/werkstuk]]></item>
  7. <item id="015071401858970545" view="12000" title="0x|Literatuur" engtitle="0x|Required reading"><![CDATA[Wayne C. Booth, Gregory G. Colomb, Joseph M. Wi$
  8. <item id="5960589172957031" view="12000" title="0x|Uitbreiding" engtitle="0x|Expansion"><![CDATA[]]></item>
  9. <item id="3610066867901779" view="12000" title="0x|Aansluiting" engtitle="0x|Place in study program"><![CDATA[]]></item>
  10. <item id="19232369892482925" view="12000" title="0x|Toegangseisen" engtitle="0x|Course requirements"><![CDATA[]]></item>
  11. <item id="3332396346891524" view="12000" title="0x|Doelgroep" engtitle="0x|Target audience"><![CDATA[]]></item>
  12. <item id="6606851872934866" view="12000" title="0x|Aanmelden bij" engtitle="0x|Enrollment at"><![CDATA[]]></item>
  13. <item id="1478643580820973" view="12000" title="0x|Informatie bij" engtitle="0x|Information at"><![CDATA[Docent]]></item>
  14. <item id="9710608434763993" view="12000" title="0x|Rooster" engtitle="0x|Schedule"><![CDATA[1e semester, maandag 15.00-17.00, zaal 1175/030]]></item>
  15. </body>
  16. </course>
  17.  
  18. $description = $xml->xpath("//item[@title='0x|Beschrijving']");
  19.  
  20. Array
  21. (
  22. [0] => SimpleXMLElement Object
  23. (
  24. [@attributes] => Array
  25. (
  26. [id] => 787900813228567
  27. [view] => 12000
  28. [title] => 0x|Beschrijving
  29. [engtitle] => 0x|Description
  30. )
  31. )
  32. )
  33.  
  34. <?php
  35. $xml = simplexml_load_file('file.xml', NULL, LIBXML_NOCDATA);
  36. $description = $xml->xpath("//item[@title='0x|Beschrijving']");
  37. var_dump($description);
  38. ?>
  39.  
  40. array(1) {
  41. [0]=>
  42. object(SimpleXMLElement)#2 (2) {
  43. ["@attributes"]=>
  44. array(4) {
  45. ["id"]=>
  46. string(15) "787900813228567"
  47. ["view"]=>
  48. string(5) "12000"
  49. ["title"]=>
  50. string(15) "0x|Beschrijving"
  51. ["engtitle"]=>
  52. string(14) "0x|Description"
  53. }
  54. [0]=>
  55. string(41) "Dit college leert studenten hoe ze een on"
  56. }
  57. }
  58.  
  59. echo $description[0];
  60.  
  61. $str = (string) $description[0];
  62.  
  63. $description = $xml->xpath("//item[@title='0x|Beschrijving']");
  64.  
  65. while(list( , $node) = each($description)) {
  66.  
  67. echo($node);
  68.  
  69. }
Add Comment
Please, Sign In to add comment