Loading XML documents into ArcSDE is similar to loading shapes and rasters, except for the use of the XML document API object.
After the XML column and indexes/tags
are created, an XML document API object is initialized, the XML document text is added to the object, and the object is inserted into the
database by the stream. For loading XML documents into a database, ArcSDE does not restrict users to inserting documents of the same codepage in a given XML column.
The following code snippets demonstrate how XML data is loaded using the C and Java APIs.
LONG rc, in_types[5], i; ////Code not verified yet
SE_COLUMN_DEF column_defs[num_columns];
CHAR tableName[SE_QUALIFIED_TABLE_NAME], index_name[SE_QUALIFIED_XML_INDEX_LEN],
*in_names[5], *config_keyword[10];
SE_XMLINDEXINFO xml_index;
BOOL buffered, has_xml;
SE_XMLTAGINFO tag;
SE_XMLCOLUMNINFO xmlcolumn;
rc = SE_table_create(connection, tableName, num_columns, column_defs, config_keyword);
/* Create an index definition for the column */
rc = SE_xmlindexinfo_create (&xml_index);
sprintf(index_name, "xml_index");
rc = SE_xmlindexinfo_set_name (xml_index, index_name);
rc = SE_xmlindexinfo_set_type (xml_index, SE_XML_INDEX_DEFINITION);
in_names[0] = "/metadata/demo/gn/suptheme";
in_names[1] = "/metadata/demo/gn/coverage";
in_names[2] = "/metadata/demo/gn/featured";
in_names[3] = "/metadata/demo@MetaID";
in_types[0] = SE_XML_INDEX_DOUBLE_TYPE;
in_types[1] = SE_XML_INDEX_STRING_TYPE;
in_types[2] = SE_XML_INDEX_STRING_TYPE;
in_types[3] = SE_XML_INDEX_DOUBLE_TYPE;
rc = SE_xmltaginfo_create (&tag);
for (i = 0; i < 4; i++){
rc = SE_xmltaginfo_set_name (tag, in_names[i]);
rc = SE_xmltaginfo_set_data_type (tag, in_types[i]);
rc = SE_xmlindexinfo_add_tag (xml_index, tag);
}
/* Create xml column */
rc = SE_xmlcolumninfo_create (&xmlcolumn);
rc = SE_xmlcolumninfo_set_xml_column (xmlcolumn, tableName, XMLCOL);
rc = SE_xmlcolumninfo_set_creation_keyword (xmlcolumn, "DEFAULTS");
rc = SE_xmlcolumninfo_set_minimum_id (xmlcolumn, 500);
rc = SE_xmlcolumninfo_set_index (xmlcolumn, xml_index);
rc = SE_xmlcolumn_create (handle, xmlcolumn);
SeConnection conn = ...
SeTable table = createTable();
int[] in_types = new int[5];
String[] in_names = new String[5];
//Create XML Index
SeXmlIndex index = new SeXmlIndex(conn);
index.setName("xml_index");
index.setDescription("index description");
index.setType(SeDefs.SE_XML_INDEX_DEFINITION);
in_names[0] = "/metadata/demo/gn/suptheme";
in_names[1] = "/metadata/demo/gn/coverage";
in_names[2] = "/metadata/demo/gn/featured";
in_names[3] = "/metadata/demo@MetaID";
in_types[0] = SeDefs.SE_XML_INDEX_DOUBLE_TYPE;
in_types[1] = SeDefs.SE_XML_INDEX_STRING_TYPE;
in_types[2] = SeDefs.SE_XML_INDEX_STRING_TYPE;
in_types[3] = SeDefs.SE_XML_INDEX_DOUBLE_TYPE;
SeXmlTag tag = new SeXmlTag();
for (int i = 0; i < 4; i++)
{
tag.setName(in_names[i]);
tag.setDataType(in_types[i]);
index.addTag(tag);
}
//Create XML Column
SeXmlColumn xmlCol=new SeXmlColumn(conn);
xmlCol.setXmlColumn(tableName, xmlColumnName);
xmlCol.setCreationKeyword("DEFAULTS");
xmlCol.setMinimumId(100);
xmlCol.setIndex(index);
xmlCol.create();
|
LONG keyval;
SE_STREAM stream;
SE_XMLDOC xmldoc;
/* Setup insert stream */
rc = SE_stream_create(handle, &stream);
rc = SE_stream_insert_table(stream, tableName, 2, columns);
rc = SE_stream_set_write_mode(stream, FALSE);
rc = SE_stream_bind_input_column(stream, 1, &keyval, SE_IS_NOT_NULL_VALUE);
rc = SE_xmldoc_create(&xmldoc);
rc = SE_xmldoc_set_text(xmldoc, strlen (XMLDOC) + 1, XMLDOC);
rc = SE_stream_set_xml(stream, 2, xmldoc);
rc = SE_stream_execute(stream);
if (buffered)
{
rc = SE_stream_flush_buffered_writes(stream);
}
rc = SE_stream_free(stream);
SE_xmldoc_free(xmldoc);
//Create XML Doc
String docXML = "....";
SeXmlDoc doc = null;
SeInsert insert = null;
SeRow row = null;
doc = new SeXmlDoc();
doc.setText(docXML);
insert = new SeInsert(conn);
insert.intoTable(table.getQualifiedName(), columns);
insert.setWriteMode(false);
row = insert.getRowToSet();
row.setXml(columnNumber, doc);
insert.execute();
insert.close();
//Clean Up: Delete column, table, close connection.
|
See also
|