Exporting metadata
You can specify
that metadata in the form of a DTD or schema should be exported
when you save the DataWindow object. You can choose to save the metadata
with the XML or in a separate file.
If you export metadata as a schema, you can associate it with
a namespace. See “Associating a namespace
with an exported schema”.
To specify how metadata should be saved, select a value from
the Meta Data Type drop-down list or set the Export.XML.MetaDataType property.
The possible values are:
-
XMLNone!—No
metadata is generated -
XMLSchema!—An XML schema is generated
-
XMLDTD!—A DTD is generated
If the data item for a column is null or
an empty string, an empty element is created. If you select XMLSchema!,
child elements with null data items are created
with the content "xsi:nil='true'".
The metadata is saved into the exported XML itself or into
an associated file, depending on the setting in the SaveMeta Data
drop-down list or the Export.XML.SaveMetaData property.
The possible values are:
-
MetaDataInternal!—The
metadata is saved into the generated XML document or string. To
save metadata using the .Data.XML expression syntax,
you must use this value. -
MetaDataExternal!—The metadata is saved
as an external file with the same name as the XML document but with
the extension .xsd (for a schema) or .dtd (for
a DTD). A reference to the name of the metadata file is included
in the output XML document.
Example: internal metadata
For example, if you select XMLDTD! and MetaDataInternal!,
the header and first row of the exported XML would look like this
for a simple grid DataWindow for the contact table
in the EAS Demo DB. The Include Whitespace
property has also been selected and the file name is dtdinternal.xml:
|
1 |
<?xml version="1.0" encoding="UTF-16LE" standalone="yes"?><br><!DOCTYPE dtdinternal [<!ELEMENT dtdinternal (dtdinternal_row*)><br><!ELEMENT dtdinternal_row (id, last_name, first_name, title, street, city, state, zip, phone, fax)><br><!ELEMENT id (#PCDATA)><br><!ELEMENT last_name (#PCDATA)><br><!ELEMENT first_name (#PCDATA)><br><!ELEMENT title (#PCDATA)><br><!ELEMENT street (#PCDATA)><br><!ELEMENT city (#PCDATA)><br><!ELEMENT state (#PCDATA)><br><!ELEMENT zip (#PCDATA)><br><!ELEMENT phone (#PCDATA)><br><!ELEMENT fax (#PCDATA)><br>]><br><dtdinternal><br>   <dtdinternal_row><br>      <id>1</id><br>      <last_name>Hildebrand</last_name><br>      <first_name>Jane</first_name><br>      <title>ma</title><br>      <street>1280 Washington St.</street><br>      <city>Emeryville</city><br>      <state>MI</state><br>      <zip>94608</zip><br>      <phone>5105551309</phone><br>      <fax>5105554209</fax><br>   </dtdinternal_row> |
Example: external metadata
If you select MetaDataExternal! instead, the generated XML
in dtdexternal.xml looks like this:
|
1 |
<?xml version="1.0" encoding="UTF-16LE"?><br><!DOCTYPE dtdexternal SYSTEM "dtdexternal.dtd"><br><dtdexternal><br>   <dtdexternal_row><br>      <id>1</id><br>      <last_name>Hildebrand</last_name><br>      <first_name>Jane</first_name><br>      <title>ma</title><br>      <street>1280 Washington St.</street><br>      <city>Emeryville</city><br>      <state>MI</state><br>      <zip>94608</zip><br>      <phone>5105551309</phone><br>      <fax>5105554209</fax><br>   </dtdexternal_row> |
The DTD is in dtdexternal.dtd:
|
1 |
<?xml version="1.0" encoding="UTF-16LE"?><!ELEMENT dtdexternal (dtdexternal_row*)><br><!ELEMENT dtdexternal_row (id, last_name, first_name, title, street, city, state, zip, phone, fax)><br><!ELEMENT id (#PCDATA)><br><!ELEMENT last_name (#PCDATA)><br><!ELEMENT first_name (#PCDATA)><br><!ELEMENT title (#PCDATA)><br><!ELEMENT street (#PCDATA)><br><!ELEMENT city (#PCDATA)><br><!ELEMENT state (#PCDATA)><br><!ELEMENT zip (#PCDATA)><br><!ELEMENT phone (#PCDATA)><br><!ELEMENT fax (#PCDATA)> |
MetaDataExternal! not supported for dot notation
The metadata cannot be saved in an external file if you use
dot notation to generate the XML.
Associating a namespace
with an exported schema
If
you export metadata in the form of a schema, you can associate a
namespace with the schema. To do so, right-click the root element
in the Export/Import template view and select Schema Options
from the pop-up menu. In the dialog box, specify the namespace prefix
and URI.
When the Meta Data Type property is XMLSchema! and the Save
Meta Data property is MetaDataInternal!, so that the XML schema
is generated inline, you can specify a name for the root element.
If the root element name is specified, it appears in the generated
XML.
In the following example, the root element name is Contacts,
the namespace prefix is po, and the URI is http://www.example.com/PO1.
The example shows the header and the first row of the generated
XML:
|
1 |
<?xml version="1.0" encoding="UTF-16LE" standalone="no"?><br><Contacts><br>  <xs:schema xmlns:po="http://www.example.com/PO1"<br>      xmlns:xs="http://www.w3.org/2001/XMLSchema"<br>      targetNamespace="http://www.example.com/PO1"<br>      elementFormDefault="qualified"<br>      attributeFormDefault="unqualified"><br>    <xs:element name="d_contact_list"><br>      <xs:complexType><br>        <xs:sequence><br>          <xs:element ref="d_contact_list_row"<br>              maxOccurs="unbounded" minOccurs="0"/><br>        </xs:sequence><br>      </xs:complexType><br>    </xs:element><br>    <xs:element name="d_contact_list_row"><br>      <xs:complexType><br>        <xs:sequence><br>          <xs:element ref="id"/><br>          <xs:element ref="last_name"/><br>          <xs:element ref="first_name"/><br>          <xs:element ref="city"/><br>          <xs:element ref="state"/><br>        </xs:sequence><br>      </xs:complexType><br>    </xs:element><br>    <xs:element name="id" type="xs:int"/><br>    <xs:element name="last_name" type="xs:string"/><br>    <xs:element name="first_name" type="xs:string"/><br>    <xs:element name="city" type="xs:string"/><br>    <xs:element name="state" type="xs:string"/><br>  </xs:schema><br>  <po:d_contact_list xmlns:po=<br>        "http://www.example.com/PO1" xmlns:xsi=<br>        "http://www.w3.org/2001/XMLSchema-instance"><br>    <po:d_contact_list_row><br>      <po:id>1</po:id><br>      <po:last_name>Hildebrand</po:last_name><br>      <po:first_name>Jane</po:first_name><br>      <po:city>Emeryville</po:city><br>      <po:state>MI</po:state><br>    </po:d_contact_list_row> |
By default, the generated XML is not associated with a namespace.