PostGIS  2.1.10dev-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 214 of file lwgeom_in_gml.c.

References gml_lwerror(), 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: