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/>');
29 SELECT xmlconcat(NULL);
30 SELECT xmlconcat(NULL, NULL);
33 SELECT xmlelement(name element,
34 xmlattributes (1 as one, 'deuce' as two),
37 SELECT xmlelement(name element,
38 xmlattributes ('unnamed and wrong'));
40 SELECT xmlelement(name element, xmlelement(name nested, 'stuff'));
42 SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
44 SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a));
46 SELECT xmlelement(name num, 37);
47 SELECT xmlelement(name foo, text 'bar');
48 SELECT xmlelement(name foo, xml 'bar');
49 SELECT xmlelement(name foo, text 'b<a/>r');
50 SELECT xmlelement(name foo, xml 'b<a/>r');
51 SELECT xmlelement(name foo, array[1, 2, 3]);
52 SET xmlbinary TO base64;
53 SELECT xmlelement(name foo, bytea 'bar');
55 SELECT xmlelement(name foo, bytea 'bar');
57 SELECT xmlelement(name foo, xmlattributes(true as bar));
58 SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as bar));
59 SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar));
60 SELECT xmlelement(name foo, xmlattributes('<>&"''' as funny, xml 'b<a/>r' as funnier));
63 SELECT xmlparse(content 'abc');
64 SELECT xmlparse(content '<abc>x</abc>');
66 SELECT xmlparse(document 'abc');
67 SELECT xmlparse(document '<abc>x</abc>');
70 SELECT xmlpi(name foo);
71 SELECT xmlpi(name xml);
72 SELECT xmlpi(name xmlstuff);
73 SELECT xmlpi(name foo, 'bar');
74 SELECT xmlpi(name foo, 'in?>valid');
75 SELECT xmlpi(name foo, null);
76 SELECT xmlpi(name xml, null);
77 SELECT xmlpi(name xmlstuff, null);
78 SELECT xmlpi(name "xml-stylesheet", 'href="mystyle.css" type="text/css"');
79 SELECT xmlpi(name foo, ' bar');
82 SELECT xmlroot(xml '<foo/>', version no value, standalone no value);
83 SELECT xmlroot(xml '<foo/>', version '2.0');
84 SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
85 SELECT xmlroot(xml '<?xml version="1.1"?><foo/>', version no value, standalone yes);
86 SELECT xmlroot(xmlroot(xml '<foo/>', version '1.0'), version '1.1', standalone no);
87 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no);
88 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value, standalone no value);
89 SELECT xmlroot('<?xml version="1.1" standalone="yes"?><foo/>', version no value);
109 SELECT xmlserialize(content data as character varying(20)) FROM xmltest;
110 SELECT xmlserialize(content 'good' as char(10));
111 SELECT xmlserialize(document 'bad' as text);
114 SELECT xml '<foo>bar</foo>' IS DOCUMENT;
115 SELECT xml '<foo>bar</foo><bar>foo</bar>' IS DOCUMENT;
116 SELECT xml '<abc/>' IS NOT DOCUMENT;
117 SELECT xml 'abc' IS NOT DOCUMENT;
118 SELECT '<>' IS NOT DOCUMENT;
121 SELECT xmlagg(data) FROM xmltest;
122 SELECT xmlagg(data) FROM xmltest WHERE id > 10;
123 SELECT xmlelement(name employees, xmlagg(xmlelement(name name, name))) FROM emp;
126 -- Check mapping SQL identifier to XML name
128 SELECT xmlpi(name ":::_xml_abc135.%-&_");
129 SELECT xmlpi(name "123");
132 PREPARE foo (xml) AS SELECT xmlconcat('<foo/>', $1);
134 SET XML OPTION DOCUMENT;
135 EXECUTE foo ('<bar/>');
138 SET XML OPTION CONTENT;
139 EXECUTE foo ('<bar/>');
140 EXECUTE foo ('good');
143 -- Test backwards parsing
145 CREATE VIEW xmlview1 AS SELECT xmlcomment('test');
146 CREATE VIEW xmlview2 AS SELECT xmlconcat('hello', 'you');
147 CREATE VIEW xmlview3 AS SELECT xmlelement(name element, xmlattributes (1 as ":one:", 'deuce' as two), 'content&');
148 CREATE VIEW xmlview4 AS SELECT xmlelement(name employee, xmlforest(name, age, salary as pay)) FROM emp;
149 CREATE VIEW xmlview5 AS SELECT xmlparse(content '<abc>x</abc>');
150 CREATE VIEW xmlview6 AS SELECT xmlpi(name foo, 'bar');
151 CREATE VIEW xmlview7 AS SELECT xmlroot(xml '<foo/>', version no value, standalone yes);
152 CREATE VIEW xmlview8 AS SELECT xmlserialize(content 'good' as char(10));
153 CREATE VIEW xmlview9 AS SELECT xmlserialize(content 'good' as text);
155 SELECT table_name, view_definition FROM information_schema.views
156 WHERE table_name LIKE 'xmlview%' ORDER BY 1;
158 -- Text XPath expressions evaluation
160 SELECT xpath('/value', data) FROM xmltest;
161 SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
162 SELECT xpath('', '<!-- error -->');
163 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>');
164 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']]);
165 SELECT xpath('//b', '<a>one <b>two</b> three <b>etc</b></a>');