When filtering XML files, you can specify which elements and attributes to extract according to the file's format ID or root element. This is useful when you want to extract only relevant text elements, such as abstracts from reports, or a list of authors from an anthology.
A root element is an element in which all other elements are contained. In the following XML sample, book
is the root element:
<?xml version="1.0" encoding="UTF-8"?> <book> <title>XML Introduction</title> <product id="33-657" status="draft">XML Tutorial</product> <chapter>Introduction to XML <para>What is HTML</para> <para>What is XML</para> </chapter> <chapter>XML Syntax <para>Elements must have a closing tag</para> <para>Elements must be properly nested</para> </chapter> </book>
For example, you could specify that when filtering files with the root element book
, the element title
is extracted as metadata, and only product
elements with a status
attribute value of draft
are extracted. When you extract an element, the child elements within the element are also extracted. For example, if you extract the element chapter
from the previous sample, the child element para
is also extracted.
You can use the
To modify settings
Call the fpFilterConfig() function with the following arguments:
Argument | Parameter |
---|---|
nType
|
KVFLT_SETXMLCONFIGINFO
|
nValue
|
0
|
pData
|
the address of the KVXConfigInfo structure |
For example:
KVXConfigInfo xinfo; /* populate xinfo */ (*fpFilterConfig)(pKVFilter, KVFLT_SETXMLCONFIGINFO, 0, &xinfo);
The filter sample program reads XML extraction settings from a configuration file that you specify with the -x
argument. This lets you try XML extraction settings without programming.
An example configuration file, kvxconfig.ini
, is provided with the Filter SDK. The file is in the directory install\OS\bin
, where install
is the installation directory and OS
is the name of the operating system.
The file contains the default element extraction settings for some XML formats. Sections from [config0]
to [config99]
show the default settings defined internally in KeyView. For example, the section [config3]
shows the default extraction settings for the format MS_Visio_XML_Fmt
. You can modify these if you wish, but in most cases you should not need to modify the settings for these formats.
To define custom extraction settings for a generic XML document, add a new section. For example, if you have an XML file you can define custom settings so that KeyView extracts specific information. The sample program expects custom sections to be named [configN]
, where N
is an integer starting at 100 and increasing by 1 for each additional file type, for example [config100]
, [config101]
, [config102]
, and so on.
To define custom settings for processing an XML file with the root element book
, you could add the following:
[config100] eKVFormat= szRoot=book szInMetaElement= szExMetaElement= szInContentElement=* szExContentElement=para szInAttribute=
This is a simple example that extracts text from all elements, except para
elements.
The following table describes the configuration options in kvxconfig.ini
. These are based on the structure KVXConfigInfo.
Configuration Option | Description |
---|---|
eKVFormat
|
The format ID as detected by the KeyView detection module. This determines the file type to which these extraction settings apply. See File Format Detection for more information on format ID values. If you are adding configuration settings for a custom XML document type, this option is not defined. |
szRoot
|
The file's root element. When the format ID is not defined, the root element is used to determine the file type to which these settings apply. To further qualify the element, specify its namespace. See Specify an Element's Namespace and Attribute. |
szInMetaElement
|
The elements extracted from the file as metadata. All other elements are extracted as text. Separate multiple entries with commas. To further qualify the element, specify its namespace, its attributes, or both. See Specify an Element's Namespace and Attribute. |
szExMetaElement
|
The child elements in the included metadata elements that are not extracted from the file as metadata. For example, the default extraction settings for the Visio XML format extract the You cannot exclude any metadata elements from the output for StarOffice files. All metadata is extracted regardless of this setting. Separate multiple entries with commas. To further qualify the element, specify its namespace, its attributes, or both. See Specify an Element's Namespace and Attribute. |
szInContentElement
|
The elements extracted from the file as content text. Enter an asterisk (*) to extract all elements including child elements. Separate multiple entries with commas. To further qualify the element, specify its namespace, its attributes, or both. See Specify an Element's Namespace and Attribute. |
szExContentElement
|
The child elements in the included content elements that are not extracted from the file as content text. Separate multiple entries with commas. To further qualify the element, specify its namespace, its attributes, or both. See Specify an Element's Namespace and Attribute. |
szInAttribute
|
The attribute values extracted from the file. If attributes are not defined here, attribute values are not extracted. Enter the namespace (if used), element name, and attribute name in the following format:
For example:
Separate multiple entries with commas. |
To further qualify an element, you can specify that the element must exist in a certain namespace, must contain a specific attribute, or both. To define the namespace and attribute of an element, enter the following:
ns_prefix:elemname@attribname=attribvalue
NOTE: Attribute values that contain spaces must be enclosed in quotation marks.
For example, the entry bg:language@id=xml
extracts a language
element in the namespace bg
that contains the attribute name id
with the value of "xml"
. This entry extracts the following element from an XML file:
<bg:language id="xml">XML is a simple, flexible text format derived from SGML</bg:language>
but does not extract:
<bg:language id="sgml">SGML is a system for defining markup languages.</bg:language>
or
<adv:language id="xml">The namespace should be a Uniform Resource Identifier (URI).</adv:language>_FT_HTML5_bannerTitle.htm