6 INSERT INTO xmltest VALUES (1, '<value>one</value>');
7 INSERT INTO xmltest VALUES (2, '<value>two</value>');
8 INSERT INTO xmltest VALUES (3, '<wrong');
10 SELECT * FROM xmltest;
13 SELECT xmlcomment('test');
14 SELECT xmlcomment('-test');
15 SELECT xmlcomment('test-');
16 SELECT xmlcomment('--test');
17 SELECT xmlcomment('te st');
20 SELECT xmlconcat(xmlcomment('hello'),
21 xmlelement(NAME qux, 'foo'),
24 SELECT xmlconcat('hello', 'you');
25 SELECT xmlconcat(1, 2);
26 SELECT xmlconcat('bad', '<syntax');
27 SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
28 SELECT xmlconcat('<?xml version="1.1"?><foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
31 SELECT xmlelement(name element,
32 xmlattributes (1 as one, 'deuce' as two),
35 SELECT xmlelement(name element,
36 xmlattributes ('unnamed and wrong'));
38 SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
40 SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
42 SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
44 SELECT xmlelement(name num, 37);
45 SELECT xmlelement(name foo, text 'bar');
46 SELECT xmlelement(name foo, xml 'bar');
47 SELECT xmlelement(name foo, text 'b<a/>r');
48 SELECT xmlelement(name foo, xml 'b<a/>r');
49 SELECT xmlelement(name foo, array[1, 2, 3]);
50 SET xmlbinary TO base64;
51 SELECT xmlelement(name foo, bytea 'bar');
53 SELECT xmlelement(name foo, bytea 'bar');
56 SELECT xmlparse(content 'abc');
57 SELECT xmlparse(content '<abc>x</abc>');
59 SELECT xmlparse(document 'abc');
60 SELECT xmlparse(document '<abc>x</abc>');
63 SELECT xmlpi(name foo);
64 SELECT xmlpi(name xml);
65 SELECT xmlpi(name xmlstuff);
66 SELECT xmlpi(name foo, 'bar');
67 SELECT xmlpi(name foo, 'in?>valid');
68 SELECT xmlpi(name foo, null);
69 SELECT xmlpi(name xml, null);
70 SELECT xmlpi(name xmlstuff, null);
71 SELECT xmlpi(name "xml-stylesheet", 'href="mystyle.css" type="text/css"');
72 SELECT xmlpi(name foo, ' bar');
75 SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
76 SELECT xmlroot(xml '<foo/>', version '2.0');
77 SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
78 SELECT xmlroot(xml '<?xml version="1.1"?><foo/>', version no value, standalone yes);
79 SELECT xmlroot(xmlroot(xml '<foo/>', version '1.0'), version '1.1', standalone no);
80 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no);
81 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no value);
82 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value);
102 SELECT xmlserialize(content data as character varying(20)) FROM xmltest;
103 SELECT xmlserialize(content 'good' as char(10));
104 SELECT xmlserialize(document 'bad' as text);
107 SELECT xml '<foo>bar</foo>' IS DOCUMENT;
108 SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
109 SELECT xml '<abc/>' IS NOT DOCUMENT;
110 SELECT xml 'abc' IS NOT DOCUMENT;
111 SELECT '<>' IS NOT DOCUMENT;
114 SELECT xmlagg(data) FROM xmltest;
115 SELECT xmlagg(data) FROM xmltest WHERE id > 10;
116 SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
119 -- Check mapping SQL identifier to XML name
121 SELECT xmlpi(name ":::_xml_abc135.%-&_");
122 SELECT xmlpi(name "123");
125 PREPARE foo (xml) AS SELECT xmlconcat('<foo/>', $1);
127 SET XML OPTION DOCUMENT;
128 EXECUTE foo ('<bar/>');
131 SET XML OPTION CONTENT;
132 EXECUTE foo ('<bar/>');
133 EXECUTE foo ('good');
136 -- Test backwards parsing
138 CREATE VIEW xmlview1 AS SELECT xmlcomment('test');
139 CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you');
140 CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&');
141 CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
142 CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>');
143 CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
144 CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
145 CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
146 CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
148 SELECT table_name, view_definition FROM information_schema.views
149 WHERE table_name LIKE 'xmlview%' ORDER BY 1;
151 -- Text XPath expressions evaluation
153 SELECT xpath('/value', data) FROM xmltest;
154 SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
155 SELECT xpath('', '<!-- error -->');
156 SELECT xpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>');
157 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']]);
158 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');