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

Commit1646586

Browse files
committed
Attached is a patch that adds the function xml_encode_special_chars to
the xml2 contrib module. It's against 8.0beta4. It's intended forcommit.Markus Bertheau <twanger@bluetwanger.de>
1 parent7af770d commit1646586

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎contrib/xml2/pgxml.sql.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
CREATE OR REPLACE FUNCTION xml_valid(text) RETURNS bool
44
AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict);
55

6+
CREATE OR REPLACE FUNCTION xml_encode_special_chars(text) RETURNS text
7+
AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict);
8+
69
CREATE OR REPLACE FUNCTION xpath_string(text,text) RETURNS text
710
AS 'MODULE_PATHNAME' LANGUAGE 'c' WITH (isStrict);
811

‎contrib/xml2/xpath.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static xmlXPathObjectPtr pgxml_xpath(text *document, xmlChar * xpath);
4040

4141

4242
Datumxml_valid(PG_FUNCTION_ARGS);
43+
Datumxml_encode_special_chars(PG_FUNCTION_ARGS);
4344
Datumxpath_nodeset(PG_FUNCTION_ARGS);
4445
Datumxpath_string(PG_FUNCTION_ARGS);
4546
Datumxpath_number(PG_FUNCTION_ARGS);
@@ -186,6 +187,34 @@ xml_valid(PG_FUNCTION_ARGS)
186187
}
187188

188189

190+
/* Encodes special characters (<, >, &, " and \r) as XML entities */
191+
192+
PG_FUNCTION_INFO_V1(xml_encode_special_chars);
193+
194+
Datum
195+
xml_encode_special_chars(PG_FUNCTION_ARGS)
196+
{
197+
text*tin=PG_GETARG_TEXT_P(0);
198+
text*tout;
199+
int32ressize;
200+
xmlChar*ts,*tt;
201+
202+
ts=pgxml_texttoxmlchar(tin);
203+
204+
tt=xmlEncodeSpecialChars(NULL,ts);
205+
206+
pfree(ts);
207+
208+
ressize=strlen(tt);
209+
tout= (text*)palloc(ressize+VARHDRSZ);
210+
memcpy(VARDATA(tout),tt,ressize);
211+
VARATT_SIZEP(tout)=ressize+VARHDRSZ;
212+
213+
xmlFree(tt);
214+
215+
PG_RETURN_TEXT_P(tout);
216+
}
217+
189218
staticxmlChar
190219
*
191220
pgxmlNodeSetToText(xmlNodeSetPtrnodeset,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp