Home    |    Concepts   |   API   |   Samples
Concepts > XML > Data Retrieval
Data Retrieval Using XPath Constraints

The ArcSDE XML API supports a subset of the XPath standard that allows users to retrieve XML data from ArcSDE using XPath constraints. Thus, in order to use the XPath constraints, the following steps must be followed:

  1. Create a queryinfo object, set the name of the column to be retrieved.
  2. Set the XPath constraint in the queryinfo object using the C function SE_queryinfo_set_xpath_constraint() or the SeQueryInfo.setXpathConstraint() Java method.
  3. Create an XML doc object, fetch the query, and retrieve the XML document (see Data Retrieval section).

If the XML document in ArcSDE satisfies the specified XPath query string, the complete XML document is returned. If not, nothing is returned.

The following code snippet illustrates the use of an XPath constraint in retrieving an XML document.

LONG rc;
SHORT col_no;
CHAR *columns[2], by_clause[128];
SE_XMLCOLUMNINFO xmlcolumn;

rc = SE_queryinfo_set_tables (qinfo, 1, &table, NULL);

sprintf (by_clause, "order by %s", XMLCOL);
rc = SE_queryinfo_set_by_clause (qinfo, by_clause);

columns[0] = XMLCOL;
col_no = 0;

rc = SE_queryinfo_set_columns (qinfo, col_no + 1, columns);
rc = SE_queryinfo_set_xpath_constraint (qinfo, table, XMLCOL, xpath_expr);
rc = SE_stream_query_with_info (stream, qinfo);
rc = SE_stream_execute (stream);
rc = SE_stream_free (stream);
SE_queryinfo_free (qinfo);

SeQuery query = new SeQuery(conn);

SeSqlConstruct sql = new SeSqlConstruct(table.getQualifiedName(), null);

SeQueryInfo qInfo = new SeQueryInfo();
qInfo.setConstruct(sql);
qInfo.setColumns(columns);

String xpathConstraint = "/metadata/qa_xpath_queries/gn[suptheme = 4]";
qInfo.setXpathConstraint(tableName, xmlColumnName, xpathConstraint);

query.prepareQueryInfo(qInfo);

//Retrieve XML doc
SeXmlDoc xmldoc = new SeXmlDoc();

query.execute();

SeRow row = query.fetch();
xmldoc = row.getXml(1);

query.close();

feedback | privacy | legal