PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ 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 227 of file lwgeom_in_gml.c.

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().

228 {
229  char *id;
230  xmlNsPtr *ns, *n;
231  xmlXPathContext *ctx;
232  xmlXPathObject *xpath;
233  xmlNodePtr node, ret_node;
234  xmlChar *href, *p, *node_id;
235 
236  href = xmlGetNsProp(xnode, (xmlChar *)"href", (xmlChar *) XLINK_NS);
237  id = lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name)
238  + xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
239  p = href;
240  p++; /* ignore '#' first char */
241 
242  /* XPath pattern look like: //gml:point[@gml:id='p1'] */
243  sprintf(id, "//%s:%s[@%s:id='%s']", (char *) xnode->ns->prefix,
244  (char *) xnode->name,
245  (char *) xnode->ns->prefix,
246  (char *) p);
247 
248  ctx = xmlXPathNewContext(xnode->doc);
249  if (ctx == NULL)
250  {
251  xmlFree(href);
252  lwfree(id);
253  return NULL;
254  }
255 
256  /* Handle namespaces */
257  ns = xmlGetNsList(xnode->doc, xnode);
258  for (n=ns ; *n; n++) xmlXPathRegisterNs(ctx, (*n)->prefix, (*n)->href);
259  xmlFree(ns);
260 
261  /* Execute XPath expression */
262  xpath = xmlXPathEvalExpression((xmlChar *) id, ctx);
263  lwfree(id);
264  if (xpath == NULL || xpath->nodesetval == NULL || xpath->nodesetval->nodeNr != 1)
265  {
266  xmlFree(href);
267  xmlXPathFreeObject(xpath);
268  xmlXPathFreeContext(ctx);
269  return NULL;
270  }
271  ret_node = xpath->nodesetval->nodeTab[0];
272  xmlXPathFreeObject(xpath);
273  xmlXPathFreeContext(ctx);
274 
275  /* Protection against circular calls */
276  for (node = xnode ; node != NULL ; node = node->parent)
277  {
278  if (node->type != XML_ELEMENT_NODE) continue;
279  node_id = gmlGetProp(node, (xmlChar *) "id");
280  if (node_id != NULL)
281  {
282  if (!xmlStrcmp(node_id, p))
283  gml_lwpgerror("invalid GML representation", 2);
284  xmlFree(node_id);
285  }
286  }
287 
288  xmlFree(href);
289  return ret_node;
290 }
void lwfree(void *mem)
Definition: lwutil.c:244
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML propertie from a node or NULL otherwise Respect namespaces if presents in the node ele...
#define XLINK_NS
Definition: lwgeom_in_gml.c:75
void * lwalloc(size_t size)
Definition: lwutil.c:229
Here is the call graph for this function:
Here is the caller graph for this function: