xml.out 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. CREATE TABLE xmltest (
  2. id int,
  3. data xml
  4. );
  5. INSERT INTO xmltest VALUES (1, '<value>one</value>');
  6. INSERT INTO xmltest VALUES (2, '<value>two</value>');
  7. SELECT * FROM xmltest;
  8. id | data
  9. ----+--------------------
  10. 1 | <value>one</value>
  11. 2 | <value>two</value>
  12. (2 rows)
  13. SELECT xmlcomment('test');
  14. xmlcomment
  15. -------------
  16. <!--test-->
  17. (1 row)
  18. SELECT xmlcomment('-test');
  19. xmlcomment
  20. --------------
  21. <!---test-->
  22. (1 row)
  23. SELECT xmlcomment('test-');
  24. ERROR: invalid XML comment
  25. SELECT xmlcomment('--test');
  26. ERROR: invalid XML comment
  27. SELECT xmlcomment('te st');
  28. xmlcomment
  29. --------------
  30. <!--te st-->
  31. (1 row)
  32. SELECT xmlagg(data) FROM xmltest WHERE id > 10;
  33. xmlagg
  34. --------
  35. (1 row)
  36. SET XML OPTION DOCUMENT;
  37. SET XML OPTION CONTENT;
  38. SELECT xml '<!-- in SQL:2006+ a doc is content too--> <?y z?> <!DOCTYPE a><a/>';
  39. xml
  40. --------------------------------------------------------------------
  41. <!-- in SQL:2006+ a doc is content too--> <?y z?> <!DOCTYPE a><a/>
  42. (1 row)
  43. SELECT xml '<?xml version="1.0"?> <!-- hi--> <!DOCTYPE a><a/>';
  44. xml
  45. ------------------------------
  46. <!-- hi--> <!DOCTYPE a><a/>
  47. (1 row)
  48. SELECT xml '<!DOCTYPE a><a/>';
  49. xml
  50. ------------------
  51. <!DOCTYPE a><a/>
  52. (1 row)
  53. SELECT xpath('//loc:piece/@id', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
  54. xpath
  55. -------
  56. {1,2}
  57. (1 row)
  58. SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
  59. xpath
  60. ------------------------------------------------------------------------------------------------------------------------------------------------
  61. {"<local:piece xmlns:local=\"http://127.0.0.1\" id=\"1\">number one</local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
  62. (1 row)
  63. SELECT xpath('//loc:piece', '<local:data xmlns:local="http://127.0.0.1" xmlns="http://127.0.0.2"><local:piece id="1"><internal>number one</internal><internal2/></local:piece><local:piece id="2" /></local:data>', ARRAY[ARRAY['loc', 'http://127.0.0.1']]);
  64. xpath
  65. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  66. {"<local:piece xmlns:local=\"http://127.0.0.1\" xmlns=\"http://127.0.0.2\" id=\"1\"><internal>number one</internal><internal2/></local:piece>","<local:piece xmlns:local=\"http://127.0.0.1\" id=\"2\"/>"}
  67. (1 row)