table_to_xml_and_xmlschema() 是一个系统函数,用于将表的内容映射到 XML 并生成描述这些映射的 XML Schema 文档。
table_to_xml_and_xmlschema() 在 PostgreSQL 8.3 中被添加。
用法
table_to_xml_and_xmlschema (tableregclass,nullsboolean,tableforestboolean,targetnstext)
→xml
table_to_xml_and_xmlschema() 结合了 table_to_xml() 和 table_to_xmlschema() 函数的输出。更多细节请参阅每个函数的条目。
变更历史
- PostgreSQL 8.3
- 已添加 (commit 355e05ab)
示例
table_to_xml_and_xmlschema() 的基本用法示例
postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE
postgres=# INSERT INTO foo VALUES(generate_series(1,2), clock_timestamp());
INSERT 0 2
postgres=# SELECT table_to_xml_and_xmlschema('foo'::regclass, true, true, '');
table_to_xml_and_xmlschema
------------------------------------------------------------------------------------------------
<xsd:schema +
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> +
+
<xsd:simpleType name="INTEGER"> +
<xsd:restriction base="xsd:int"> +
<xsd:maxInclusive value="2147483647"/> +
<xsd:minInclusive value="-2147483648"/> +
</xsd:restriction> +
</xsd:simpleType> +
+
<xsd:simpleType name="UDT.postgres.pg_catalog.text"> +
<xsd:restriction base="xsd:string"> +
</xsd:restriction> +
</xsd:simpleType> +
+
<xsd:complexType name="RowType.postgres.public.foo"> +
<xsd:sequence> +
<xsd:element name="id" type="INTEGER" nillable="true"></xsd:element> +
<xsd:element name="val" type="UDT.postgres.pg_catalog.text" nillable="true"></xsd:element>+
</xsd:sequence> +
</xsd:complexType> +
+
<xsd:element name="foo" type="RowType.postgres.public.foo"/> +
+
</xsd:schema> +
+
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +
<id>2</id> +
<val xsi:nil="true"/> +
</foo> +
+
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +
<id>1</id> +
<val xsi:nil="true"/> +
</foo> +
+
(1 row)
参考资料
- PostgreSQL 文档: 将表映射到 XML
另请参阅
table_to_xml(), table_to_xmlschema(), query_to_xml_and_xmlschema(), cursor_to_xml_and_xmlschema(), database_to_xml_and_xmlschema(), schema_to_xml_and_xmlschema()
