Start page

Mykola Zharkikh (Kyiv)

Personal site

?

Data import

To import data one should register in Smereka as editor, then switch to edit mode, choose the node, which will be relative base for imported nodes, and click the button «Import» on the toolbar to the left of the inspector.

This button invokes import settings dialog. This dialog lets you specify the following parameters: the position of insertion, data type in the input field, data encoding, data element name. Half of the dialog box takes input field.

Selector «Position of insertion» contains the options: the first node, before the current, after the current, last node, a child node.

Selector «What import» contains the options: File, Text.

Selector «Encoding» contains options: Win-1251, UTF-8.

Window «Element» contains data element name for import.

In the input field should be placed data for import.

Please be aware that the import operation is quite complex and detailed behavior depends not only on the settings in dialog, but on data as well.

Importing text

If selectors «What import» set as Text, Smereka treat the content of input field as literal text data for import.

Method of processing the text determined by signatures.

If the text begins with the characters <?xml and contains the line xmlns="https://www.m-zharkikh.name/xml/Smereka/Import.xsd", text is assumed to be Smereka XML text and processed as explained below.

If the text contains a string <html> and «Element» is provided, text is assumed to be HTML text and processed as explained below.

If the signature is found, the text is assumed to be plain; Smereka creates a new node of Information class and put the text to the HTMLCode attribute for that language version, which is current at the time of import.

Import Smereka XML text

When one import Smereka XML text, the selectors «Encoding» is ignored, text encoding is determined as specified in the header of an XML document.

Using the nodes ID-s. If the document contains absolute node id-s (for example, <Node id="1104">), Smereka will create new nodes with these ID-s (or overwrite existing nodes). If the document contains the relative node ID-s (for example, <Node id="Ref1104">), Smereka will create new nodes with ordinary ID-s, while the existing nodes will not be modified.

Use parent attribute. Consider the next options.

1. Attribute parent is not provided. In this case, imported node will be placed as determined by «Paste Position» selector.

2. Attribute is set to absolute value, e.g. <parent Target="1055" />. In this case new node becomes the child of the «parent» node, «Paste position» selector is ignored.

2. Attribute is set to relative value, e.g. <parent Target="Ref1055" />. If the node with such relative id is present in the imported node set, a new node becomes the cnild of this node, otherwise the integer value is extracted from attribute (in this example – 1055) and it is treated as absolute value.

3. Using class and Template attributes. These attributes are pointers to the Smereka metaobjects, so they can be set with absolute or relative addressing, such as <class Target="Ref52" />, <Template Target="97" />. But to make XML text more human-readable (not a program-readable!) they can be set as a symbolic names, such as <class>Information</class>, <Template>Default</Template> where appear symbolic names of metaclasses or metatemplates respectively.

So, when you import XML text Smereka creates as many nodes, as recorded in XML file. With other types of text import only one node created from one text.

Import HTML text

If the text is recognized as HTML text, its encoding is determined on the basis of Content-Type declaration, e.g. <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">. Selector «Encoding» is ignored.

Smereka examines the structure of a document and search the item with «Element» identifier. If the element is found, Smereka creates a new node of Information class and includes an internal HTML code of the element to the HTMLCode attribute for that language version, which is current at the time of import.

For example, if a given data item name MainText and HTML code contain an item <div id="MainText"> so contetn of this div will be imported.

If requested element is not found, Smereka import entire HTML code as plain text.

Import files

If «What import» selector is set to a File, Smereka treat the content of input field as a list of files (one file per line).

Each line may represent a local file name, local directory name or URL.

If a line is recognized as a URL, Smereka download this file and then treats it as a text document (with rules set out above). In this version of Smereka does not support import image files through the URL. If the URL indicates a directory on another server, Smereka can not handle it.

If a line is recognized as a local file, Smereka verifies signatures of the graphic formats GIF, JPG, PNG. If the signatures are found, Smereka creates a new node of Image class and writes the file name as its Image attribute. Under certain conditions Smereka can automatically create small images (thumbnails), which can then be used, for example, when building galleries.

If the image signature is not found, Smereka treats file as a text document (with the rules set out above).

If a line is recognized as a local directory, Smereka build a hierarchical list of files and directories that it contains, to complete exhaustion of all sub-directories. Then each element of the list is processed by the rules set out above for import local files. To list items that represent directories, Smereka creating node of Information class and put nested in the directory files and directories as child nodes. Thus, during the import directory Smereka create node tree, isomorphic to the filesystem tree.

So, import of one directory could create a hundreds of nodes, which may be of great convenience in handling similar documents.