PostGIS  2.2.7dev-r@@SVN_REVISION@@
static xmlNodePtr get_xlink_node ( xmlNodePtr  xnode)
static

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

Definition at line 213 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().

214 {
215  char *id;
216  xmlNsPtr *ns, *n;
217  xmlXPathContext *ctx;
218  xmlXPathObject *xpath;
219  xmlNodePtr node, ret_node;
220  xmlChar *href, *p, *node_id;
221 
222  href = xmlGetNsProp(xnode, (xmlChar *)"href", (xmlChar *) XLINK_NS);
223  id = lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name)
224  + xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
225  p = href;
226  p++; /* ignore '#' first char */
227 
228  /* XPath pattern look like: //gml:point[@gml:id='p1'] */
229  sprintf(id, "//%s:%s[@%s:id='%s']", (char *) xnode->ns->prefix,
230  (char *) xnode->name,
231  (char *) xnode->ns->prefix,
232  (char *) p);
233 
234  ctx = xmlXPathNewContext(xnode->doc);
235  if (ctx == NULL)
236  {
237  xmlFree(href);
238  lwfree(id);
239  return NULL;
240  }
241 
242  /* Handle namespaces */
243  ns = xmlGetNsList(xnode->doc, xnode);
244  for (n=ns ; *n; n++) xmlXPathRegisterNs(ctx, (*n)->prefix, (*n)->href);
245  xmlFree(ns);
246 
247  /* Execute XPath expression */
248  xpath = xmlXPathEvalExpression((xmlChar *) id, ctx);
249  lwfree(id);
250  if (xpath == NULL || xpath->nodesetval == NULL || xpath->nodesetval->nodeNr != 1)
251  {
252  xmlFree(href);
253  xmlXPathFreeObject(xpath);
254  xmlXPathFreeContext(ctx);
255  return NULL;
256  }
257  ret_node = xpath->nodesetval->nodeTab[0];
258  xmlXPathFreeObject(xpath);
259  xmlXPathFreeContext(ctx);
260 
261  /* Protection against circular calls */
262  for (node = xnode ; node != NULL ; node = node->parent)
263  {
264  if (node->type != XML_ELEMENT_NODE) continue;
265  node_id = gmlGetProp(node, (xmlChar *) "id");
266  if (node_id != NULL)
267  {
268  if (!xmlStrcmp(node_id, p))
269  gml_lwpgerror("invalid GML representation", 2);
270  xmlFree(node_id);
271  }
272  }
273 
274  xmlFree(href);
275  return ret_node;
276 }
void lwfree(void *mem)
Definition: lwutil.c:214
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:67
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:61
void * lwalloc(size_t size)
Definition: lwutil.c:199

Here is the call graph for this function:

Here is the caller graph for this function: