An XML document is a hierarchically structured text document consisting
of labels (called tags) and data. The XML doc entity is used as a placeholder
for XML documents that are stored into or retrieved from the database by ArcSDE.
The ArcSDE API uses the XML Document object (SeXmlDoc in Java, SE_xml_doc*
functions in C) to store and retrieve an XML document from ArcSDE. ArcSDE
Insert and Query stream objects communicate with the XML Document object, which
in turn is associated with the XML column.
Storage
In ArcSDE, an XML document is always stored in a BLOB and can be stored in compressed or uncompressed form. By default, the document is stored in compressed form.
This can be changed by using the XML_DOC_UNCOMPRESSED_TYPE DBTUNE parameter.
The XML_DOC_UNCOMPRESSED_TYPE has three possible values:
- BinaryThis is the default setting. The XML Document is stored in a DBMS BLOB (LOB in Oracle, IMAGE in SQL Server) column. This type must be used if the user
is storing documents that are a mix of codepages or that do not match their client locale
or their database locale. By
storing the doc in a binary column, there are no codepage conversion issues and all docs will be stored safely.
- TextThe doc is stored in a DBMS
long text column (CLOB in Oracle, TEXT in SQL Server). This type can be used if the users locale and the encoding for all
XML docs that will be stored match exactly, and this codepage is an ANSI (not
Unicode) codepage. Also, the codepage must be supported by the underlying database text type.
Any deviation from this will result either in an error or garbage characters being stored.
For example, if a
UNIX client in an eastern European codepage (ISO8859-2 on UNIX) tries to store data on a
Windows server that is also eastern European (WIN1250 on
Windows), this will work provided the XML document is encoded in the client codepage (ISO8859-2) not the server codepage (WIN1250). Even though both are the same
language, they are different encodings. In the above example, the NLS_LANG environment variable will tell the
DBMS to convert from ISO8859-2 to WIN1250 (assuming that
the database was also setup in WIN1250).
- UnicodeThe doc will be stored in a DBMS long Unicode column (Oracle NCLOB, SQL Server NTEXT). The restrictions on the use of this column are the same as TEXT, but for
Unicode codepages, not ANSI. However, with Unicode it does not matter what the databases codepage is since anything can be converted to the underlying
Unicode column. But the
client locale and xml document must still match exactly.
The following code snippets show how an XML Doc object is used to store and retrieve an XML document.
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.
|
LONG rc, keyval, key_index;
SHORT keyind, xmlind, col_no;
CHAR xml_text[1024];
SE_XMLDOC xmldoc;
*rows = 0;
rc = SE_stream_bind_output_column (stream, 1, &keyval, &keyind);
rc = SE_xmldoc_create (&xmldoc);
col_no = 1;
rc = SE_stream_bind_output_column (stream, ++col_no, xmldoc, &xmlind);
rc = SE_stream_fetch (stream);
rc = SE_xmldoc_get_text (xmldoc, xml_text);
SE_xmldoc_free (xmldoc);
SeXmlDoc xmldoc = new SeXmlDoc();
SeRow row = query.fetch();
xmldoc = row.getXml(column_num);
query.close();
|
|