Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit614e423

Browse files
committed
Add missing xml files.
1 parent31f4b59 commit614e423

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

‎contrib/xml/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# $Header: /cvsroot/pgsql/contrib/xml/Attic/Makefile,v 1.7 2004/03/05 04:10:11 momjian Exp $
2+
3+
subdir = contrib/xml
4+
top_builddir = ../..
5+
include$(top_builddir)/src/Makefile.global
6+
7+
MODULE_big = pgxml_dom
8+
OBJS = pgxml_dom.o
9+
SHLIB_LINK = -lxml2
10+
DATA_built = pgxml_dom.sql
11+
DOCS = README.pgxml
12+
13+
include$(top_srcdir)/contrib/contrib-global.mk

‎contrib/xml/README.pgxml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
This package contains some simple routines for manipulating XML
2+
documents stored in PostgreSQL. This is a work-in-progress and
3+
somewhat basic at the moment (see the file TODO for some outline of
4+
what remains to be done).
5+
6+
At present, two modules (based on different XML handling libraries)
7+
are provided.
8+
9+
Prerequisite:
10+
11+
pgxml.c:
12+
expat parser 1.95.0 or newer (http://expat.sourceforge.net)
13+
14+
or
15+
16+
pgxml_dom.c:
17+
libxml2 (http://xmlsoft.org)
18+
19+
The libxml2 version provides more complete XPath functionality, and
20+
seems like a good way to go. I've left the old versions in there for
21+
comparison.
22+
23+
Compiling and loading:
24+
----------------------
25+
26+
The Makefile only builds the libxml2 version.
27+
28+
To compile, just type make.
29+
30+
Then you can use psql to load the two function definitions:
31+
\i pgxml_dom.sql
32+
33+
34+
Function documentation and usage:
35+
---------------------------------
36+
37+
pgxml_parse(text) returns bool
38+
parses the provided text and returns true or false if it is
39+
well-formed or not. It returns NULL if the parser couldn't be
40+
created for any reason.
41+
42+
pgxml_xpath (XQuery functions) - differs between the versions:
43+
44+
pgxml.c (expat version) has:
45+
46+
pgxml_xpath(text doc, text xpath, int n) returns text
47+
parses doc and returns the cdata of the nth occurence of
48+
the "simple path" entry.
49+
50+
However, the remainder of this document will cover the pgxml_dom.c version.
51+
52+
pgxml_xpath(text doc, text xpath, text toptag, text septag) returns text
53+
evaluates xpath on doc, and returns the result wrapped in
54+
<toptag>...</toptag> and each result node wrapped in
55+
<septag></septag>. toptag and septag may be empty strings, in which
56+
case the respective tag will be omitted.
57+
58+
Example:
59+
60+
Given a table docstore:
61+
62+
Attribute | Type | Modifier
63+
-----------+---------+----------
64+
docid | integer |
65+
document | text |
66+
67+
containing documents such as (these are archaeological site
68+
descriptions, in case anyone is wondering):
69+
70+
<?XML version="1.0"?>
71+
<site provider="Foundations" sitecode="ak97" version="1">
72+
<name>Church Farm, Ashton Keynes</name>
73+
<invtype>watching brief</invtype>
74+
<location scheme="osgb">SU04209424</location>
75+
</site>
76+
77+
one can type:
78+
79+
select docid,
80+
pgxml_xpath(document,'//site/name/text()','','') as sitename,
81+
pgxml_xpath(document,'//site/location/text()','','') as location
82+
from docstore;
83+
84+
and get as output:
85+
86+
docid | sitename | location
87+
-------+--------------------------------------+------------
88+
1 | Church Farm, Ashton Keynes | SU04209424
89+
2 | Glebe Farm, Long Itchington | SP41506500
90+
3 | The Bungalow, Thames Lane, Cricklade | SU10229362
91+
(3 rows)
92+
93+
or, to illustrate the use of the extra tags:
94+
95+
select docid as id,
96+
pgxml_xpath(document,'//find/type/text()','set','findtype')
97+
from docstore;
98+
99+
id | pgxml_xpath
100+
----+-------------------------------------------------------------------------
101+
1 | <set></set>
102+
2 | <set><findtype>Urn</findtype></set>
103+
3 | <set><findtype>Pottery</findtype><findtype>Animal bone</findtype></set>
104+
(3 rows)
105+
106+
Which produces a new, well-formed document. Note that document 1 had
107+
no matching instances, so the set returned contains no
108+
elements. document 2 has 1 matching element and document 3 has 2.
109+
110+
This is just scratching the surface because XPath allows all sorts of
111+
operations.
112+
113+
Note: I've only implemented the return of nodeset and string values so
114+
far. This covers (I think) many types of queries, however.
115+
116+
John Gray <jgray@azuli.co.uk> 16 August 2001
117+
118+

‎contrib/xml/pgxml.sql.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- SQL for XML parser
2+
3+
-- Adjust this setting to control where the objects get created.
4+
SET search_path TO public;
5+
6+
CREATE OR REPLACE FUNCTION pgxml_parse(text) RETURNS boolean
7+
AS 'MODULE_PATHNAME' LANGUAGE c STRICT;
8+
9+
CREATE OR REPLACE FUNCTION pgxml_xpath(text, text, text, text) RETURNS text
10+
AS 'MODULE_PATHNAME' LANGUAGE c STRICT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp