canonicalization.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --TEST--
  2. Test: Canonicalization - C14N()
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. $xml = <<<EOXML
  8. <?xml version="1.0" encoding="ISO-8859-1" ?>
  9. <foo xmlns="http://www.example.com/ns/foo"
  10. xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test"><contain>
  11. <bar><test1 /></bar>
  12. <bar><test2 /></bar>
  13. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3 /></fubar:bar>
  14. <fubar:bar><test4 /></fubar:bar>
  15. <!-- this is a comment -->
  16. </contain>
  17. </foo>
  18. EOXML;
  19. $dom = new DOMDocument();
  20. $dom->loadXML($xml);
  21. $doc = $dom->documentElement->firstChild;
  22. /* inclusive/without comments first child element of doc element is context. */
  23. echo $doc->C14N()."\n\n";
  24. /* exclusive/without comments first child element of doc element is context. */
  25. echo $doc->c14N(TRUE)."\n\n";
  26. /* inclusive/with comments first child element of doc element is context. */
  27. echo $doc->C14N(FALSE, TRUE)."\n\n";
  28. /* exclusive/with comments first child element of doc element is context. */
  29. echo $doc->C14N(TRUE, TRUE)."\n\n";
  30. /* exclusive/without comments using xpath query. */
  31. echo $doc->c14N(TRUE, FALSE, array('query'=>'(//. | //@* | //namespace::*)'))."\n\n";
  32. /* exclusive/without comments first child element of doc element is context.
  33. using xpath query with registered namespace.
  34. test namespace prefix is also included. */
  35. echo $doc->c14N(TRUE, FALSE,
  36. array('query'=>'(//a:contain | //a:bar | .//namespace::*)',
  37. 'namespaces'=>array('a'=>'http://www.example.com/ns/foo')),
  38. array('test'))."\n\n";
  39. /* exclusive/without comments first child element of doc element is context.
  40. test namespace prefix is also included */
  41. echo $doc->C14N(TRUE, FALSE, NULL, array('test'));
  42. ?>
  43. --EXPECT--
  44. <contain xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test">
  45. <bar><test1></test1></bar>
  46. <bar><test2></test2></bar>
  47. <fubar:bar><test3></test3></fubar:bar>
  48. <fubar:bar><test4></test4></fubar:bar>
  49. </contain>
  50. <contain xmlns="http://www.example.com/ns/foo">
  51. <bar><test1></test1></bar>
  52. <bar><test2></test2></bar>
  53. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
  54. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
  55. </contain>
  56. <contain xmlns="http://www.example.com/ns/foo" xmlns:fubar="http://www.example.com/ns/fubar" xmlns:test="urn::test">
  57. <bar><test1></test1></bar>
  58. <bar><test2></test2></bar>
  59. <fubar:bar><test3></test3></fubar:bar>
  60. <fubar:bar><test4></test4></fubar:bar>
  61. <!-- this is a comment -->
  62. </contain>
  63. <contain xmlns="http://www.example.com/ns/foo">
  64. <bar><test1></test1></bar>
  65. <bar><test2></test2></bar>
  66. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
  67. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
  68. <!-- this is a comment -->
  69. </contain>
  70. <foo xmlns="http://www.example.com/ns/foo"><contain>
  71. <bar><test1></test1></bar>
  72. <bar><test2></test2></bar>
  73. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
  74. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
  75. </contain>
  76. </foo>
  77. <contain xmlns="http://www.example.com/ns/foo" xmlns:test="urn::test"><bar></bar><bar></bar></contain>
  78. <contain xmlns="http://www.example.com/ns/foo" xmlns:test="urn::test">
  79. <bar><test1></test1></bar>
  80. <bar><test2></test2></bar>
  81. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test3></test3></fubar:bar>
  82. <fubar:bar xmlns:fubar="http://www.example.com/ns/fubar"><test4></test4></fubar:bar>
  83. </contain>