PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ get_xlink_node()

static xmlNodePtr get_xlink_node ( xmlNodePtr  xnode)
static

Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.

Definition at line 251 of file lwgeom_in_gml.c.

252{
253 char *id;
254 xmlNsPtr *ns, *n;
255 xmlXPathContext *ctx;
256 xmlXPathObject *xpath;
257 xmlNodePtr node, ret_node;
258 xmlChar *href, *p, *node_id;
259
260 href = xmlGetNsProp(xnode, (xmlChar *)"href", (xmlChar *) XLINK_NS);
261 p = href;
262 p++; /* ignore '#' first char */
263
264 if (xnode->ns)
265 {
266 id = lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name) +
267 xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
268 /* XPath pattern look like: //gml:point[@gml:id='p1'] */
269 sprintf(id, "//%s:%s[@%s:id='%s']",
270 (char *) xnode->ns->prefix,
271 (char *) xnode->name,
272 (char *) xnode->ns->prefix,
273 (char *) p);
274 }
275 else
276 {
277 id = lwalloc((xmlStrlen(xnode->name) +
278 xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
279 /* XPath pattern look like: //gml:point[@gml:id='p1'] */
280 sprintf(id, "//%s[@id='%s']",
281 (char *) xnode->name,
282 (char *) p);
283 }
284
285 ctx = xmlXPathNewContext(xnode->doc);
286 if (ctx == NULL)
287 {
288 xmlFree(href);
289 lwfree(id);
290 return NULL;
291 }
292
293 /* Handle namespaces */
294 ns = xmlGetNsList(xnode->doc, xnode);
295 for (n=ns ; *n; n++) xmlXPathRegisterNs(ctx, (*n)->prefix, (*n)->href);
296 xmlFree(ns);
297
298 /* Execute XPath expression */
299 xpath = xmlXPathEvalExpression((xmlChar *) id, ctx);
300 lwfree(id);
301 if (xpath == NULL || xpath->nodesetval == NULL || xpath->nodesetval->nodeNr != 1)
302 {
303 xmlFree(href);
304 xmlXPathFreeObject(xpath);
305 xmlXPathFreeContext(ctx);
306 return NULL;
307 }
308 ret_node = xpath->nodesetval->nodeTab[0];
309 xmlXPathFreeObject(xpath);
310 xmlXPathFreeContext(ctx);
311
312 /* Protection against circular calls */
313 for (node = xnode ; node != NULL ; node = node->parent)
314 {
315 if (node->type != XML_ELEMENT_NODE) continue;
316 node_id = gmlGetProp(node, "id");
317 if (node_id != NULL)
318 {
319 if (!xmlStrcmp(node_id, p))
320 gml_lwpgerror("invalid GML representation", 2);
321 xmlFree(node_id);
322 }
323 }
324
325 xmlFree(href);
326 return ret_node;
327}
void * lwalloc(size_t size)
Definition lwutil.c:227
void lwfree(void *mem)
Definition lwutil.c:248
static xmlChar * gmlGetProp(xmlNodePtr xnode, const char *charProp)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
#define XLINK_NS
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)

References gml_lwpgerror(), gmlGetProp(), lwalloc(), lwfree(), and XLINK_NS.

Referenced by parse_gml_coll(), parse_gml_curve(), parse_gml_data(), parse_gml_line(), parse_gml_linearring(), parse_gml_mcurve(), parse_gml_mline(), parse_gml_mpoint(), parse_gml_mpoly(), parse_gml_msurface(), parse_gml_point(), parse_gml_polygon(), parse_gml_psurface(), parse_gml_surface(), parse_gml_tin(), and parse_gml_triangle().

Here is the call graph for this function:
Here is the caller graph for this function: