[an error occurred while processing this directive]

The header of XMLtable, footer processing API


1. Processing summary

XMLtable, has consisted from three elements of header, body and footer, (the explanation whose XMLtable is detailed). Information as the dictionary regarding the data of the table type which is described to body (title and item name etc.) is described to header. Here, the API explanation regarding header and footer is done.

The input process of header

It is very simple to read the header information of XMLtable from the input data. As the reading function of header,"mssReadHeader " function is prepared. If the information of XMLtable is read once, then, access method to those information just is known.

The output process of header

In addition, about input it is not simple concerning the output of XMLtable. It is necessary in memory to keep constructing header from one. It copies the header information of the input data, it makes new item name and the information of sort reflect are appointed with option, it is necessary completely to create item information anew the time. For these processing, with MUSASHI various functions are prepared. Once, if header information is constructed in memory, the outputjust calls"mssWriteHeader " function is OK.

The input-output processing of footer

With XMLtable1.1, it does not utilize the footer element. It means in the future to utilize probably will be. However, </xmltable> and the like it writes out the terminal information of the data with "mssWriteFooter" function.

2. The input process of header

In order to read header of the input data, it is necessary first to open the input file. As for details, at the paragraph of input process you explain, but it does opening the input file as follows.

Struct mssFPR *fpr; Fpr=mssOpenFPR 
("sample11.xt",4);

The buffer structure for the input data (mssFPR) it defines, appointing file name, it just calls mssOpenFPR function, (as for 2nd parameter "4", the number of ring buffers). MssOpenFPR function returns the pointer to the data reading ™E buffer structure, (it is set to fpr).

2.1. Reading of header information ™E

And, it calls "mssReadHeader " function in order to read headerfromthe input file which is opened various information of the header, the mssHeader structure (below,it is called the headerstructure) sets.

Prescribed form: Struct mssHeader * mssReadHeader (struct mssFPR *fp)

First argument: Arrangement of address of option variable
Returning value: Header structure

The cord/code becomes as follows.

Struct mssHeader *hdi; Hdi=mssReadHeader (fpr);

2.2. Access to header information

With this, it completes the reading ™E of header information.
Then next, it will keep seeing concerning the method in order to access each information.
First content of the header structure will be verified.

Struct mssHeader {struct mssFields * flds; /* item 
information * char * title; /* title character string * char * 
comment; The /* comment character string (carriage return is 
retained) * int version; The version of /*xmlTable (1.0->10, 
1.1->11) * char * xmlver; /*XML version * char * xmlenc; 
/*XML encoding * int datTop; Until the /* actual data 
starts, the number of letters * int recCnt; When the number of 
/* record lines (there is no information is, -1) *};

The other than of first variable flds of structural internal is simple.
<title> the tag of the header, <comment> the character string which is enclosed with the tag is set to title and comment.
The integer value which if bet 10 on the version of XMLtable is set to version, (<xmltable version= "1.1" >, 11).
Version and encoding of each one XML are set with the character string to xmlver and xmlenc, (<? Xml version= "1.0" encoding= "euc-jp"? If > is, xmlver= "1.0", xmlenc= "euc-jp").
Size of the header is set to datTop at integer value of the byte unit, (there are no times when it utilizes, probably will be).
As for last recCnt you just have prepared for experimental utilization being, please ignore.
With the continuation of the above-mentioned example, the cord/code which for example indicates the title of XMLtable becomes as follows, probably will be.

Printf ("title=%s¢@n" and hdi->title);

2.3. Access to item information

Well, next it will keep seeing concerning the remaining mssFields structure. The mssFiels structure (below,the plural item structures) it has become like below.

Struct mssFields {struct mssFldInfo **fi; The 
pointer arrangement to /*mssFldInfo * int cnt; The number of /* 
items *};

As for the plural item structures, the structure in order to house one item item of information (mssFldInfo: Below,it calls the iteminformation structure body) to pointer arrangement and the number of array elements (the number of items) it consists. Then, you will try looking at the content of the item information structure body.

Struct mssFldInfo {int num; /* item number (it 
starts from 0) * char *name; /* item name * int priority; 
Key priority number of /* sort (it starts from 1, it is not 0) *
int revFlg; /* reverse sort flag (0 or 1) * int numFlg; /*
numerical sort flag (0 or 1) * int length; When item length at 
the time of /* fixed length (there is no information is, 0) * char 
*comment; When comment of /* item (there is no information is, 
NULL) *};

In this structure, information concerning one item is housed. Meaning of the respective variable is as follows.

Variable identifier Example of the element or attribute which corresponds Explanation
Num <fields num= "1" > In the data of table type inside the body element, the item number which corresponds is housed. Num attribute of the fields element (<fields num= "1" >), it is the expectation where the number which starts from 1 is set, (from item the left 1,2,3 you call in order correspondence). But, in num, the integer which pulled 1 from the number, namely, 0,1,2.. Is set (with C language, as for arrangement as the one which starts from 0 is convenient, but as for the human counting from 1 normal.With the API of MUSASHI as for item number please count from everything 0).
Name <fields name= "customer number" > Name of item is set.
Priority <fields sort= "1" > If the data is sorted, the preferential key number is set. For example, if customer number, it is sorted in order of date, each one priority=1, priority=2 is set. The item which does not have relationship in the sort key (the item which is not sort attribute) with, priority=0 it is set.
RevFlg <fields reverse= "1" > When the data is sorted, if with reverse it is sorted, revFlg=1 it becomes, so is not, (the item which does not have reverse attribute) revFlg=0 it is set.
NumFlg <fields numeric= "1" > When the data is sorted, if it is sorted, as numerical value numFlg=1 it becomes, so is not, (the item which does not have numeric attribute) numFlg=0 it is set.

Well in order to access these variables, very troublesome operation becomes necessary. For example, to obtain the name of the third item which is housed in the header structure, it becomes as follows.

Char *name= (* (hdi->flds->fi+3)) ->name;

Then, with MUSASHI, we have defined macro in order to access various data of item of the n turn eye of the plural item structures, from it reaches the point where you can describe in the form which will be been clear by utilizing this macro. The macro which is accessed the respective item information is as follows.

Variable identifier of access mssFieldInfo structure Making use of macro, the method accessing 3rd item information
Num
Int num=MssFlds2num (hdi->flds,3);
Name
Char *name=MssFlds2name (hdi->flds,3);
Priority
Int priority=MssFlds2priority (hdi->flds,3);
RevFlg
Int revFlg=MssFlds2revFlg (hdi->flds,3);
NumFlg
Int numFlg=MssFlds2numFlg (hdi->flds,3);

When the structure which appears to here is rearranged,"the header structure -> the plural item structures -> please verifythat it becomes the relationship, item information structure body ".

2.4. <field> value of line and num attribute of the tag of XMLtable

It will try thinking here concerning following kind of XMLtable.

<? Xml version= "1.0" encoding= "euc-jp"? > <!
DOCTYPE xmltbl SYSTEM "xmltbl-1.1.dtd" > <xmltbl version= "1.1" 
> <header> <title> customer buying quantity amount classified by day 
</title> <comment>XMLtable sample data </comment> <field no= "2" name=
"customer name" ></field> <field no= "1" name= "customer number" sort=
"1" ></field> <field no= "3" name= "date" ></field> <field no= "4" 
name= "buying quantity" ></field> <field no= "5" name= "buying amount"
sort= "2" numeric= "1" reverse= "1" ></field> </header> <body><! 
[ CDATA [ 100 Miyamoto Musashi 20010509 1 459 100 Miyamoto 
Musashi 20010811 1 341 100 Miyamoto Musashi 20010423 1 271

The point which would like to have noting here <field> is no attribute of the tag. Customer name with 2nd item, customer number has become 1st item, making associate with the data of the table, being to be correct, it does, but appearance order of the field tag has become opposite. As for this in regard to the definition of XMLtable, there are no many problems. But when being read to the header structure, appearance order of the field tag it is set that way. Namely, in order of the item information structure body which is set to the plural item structures and value of num variable of the item information structure body, it means without being many relationships. When the above-mentioned example is read with mssReadHeader, it becomes as follows.

Formula Value
MssFlds2num (hdi->flds,0)
1
MssFlds2name (hdi->flds,0)
Customer name
MssFlds2num (hdi->flds,1)
0
MssFlds2name (hdi->flds,1)
Customer number

MssFlds2num (flds and n), it means returningthe item number which in the plural item structures the register (element number of arrangement) is done to the last in the n turn eye. It is complicated, is, but there is no mistake, the sea urchin.

2.5. The method from item number and item name of accessing item information

Here, not to be element number of arrangement, the method from item number and item name of accessing item information is introduced. With MUSASHI two functions, mssFldNum2Add and mssFldNam2Add are prepared.

Prescribed form: Struct mssFldInfo * mssFldNum2Add (struct mssFields *flds and int num)
First argument: The plural item structures which become the access object
Second argument: The item number which it accesses
Returning value: The item information structure body which corresponds

Struct mssFldInfo * mssFldNam2Add (struct mssFields *flds and char *name);
First argument: The plural item structures which become the access object
Second argument: The item name which it accesses
Returning value: The item information structure body which corresponds

The sample which used the data of the above-mentioned "Miyamoto Musashi" is shown.

Formula Value
MssFldNum2Add (hdi->flds,0) ->name
Item number
MssFldNam2Add (hdi->flds, "customer number") 
->num
0
MssFldNum2Add (hdi->flds,2) ->name
Date
MssFldNam2Add (hdi->flds, "date") ->num
2

2.6. Sample program

Below, C source of the sample which makes the contents reflect which are explained here (readheader.c) it publishes.
Please refer tothe utilization method of the sample program and compile and verify operation.

#include <stdio.h> #include <signal.h> #include 
<musashi.h> struct mssComHelp comHelp= {"readheader" and /* command 
name * "1.0", /* version * "the header input of XMLtable" and /* 
command title * "this is the sample program,", /* summary * 
"readheader -i input.xt" and /* utilization example * "writeheader" 
and /* reference command * "hambear" and /* writer information * the 
information "of musashi-users@lists.sourceforge.jp" and the /* bug 
report * "the musashi.sourceforge.jp" /* home page *}; Extern 
struct mssGlobalVariables mssGV; Int main (int argc and char 
*argv [ ]) {MssOptINF optINF= {OINF and /* option type * "i", /* 
keyword (as for plural letters failure) * 1, /* 0: Option, 1: 
Necessity * the maximum number of files of 1, /* designated 
possibilities * it does not end with the error of 0, /*1:file not 
found 0: * "Input file name", title of this option of the /* 
(indication) * "the XMLtable data is appointed" this option of the /* 
comments with Help (with Help indication) *}; Void *opt [ ] = 
{&optINF and NULL}; Struct mssFPR *fpr; /* input file 
structure * struct mssHeader *hdi; For /* input file <head> tag 
housing structure * int i; MssInit (argc, argv and &comHelp); 
Initialization & mssHelpDoc such as /* signal processing (opt, 
&comHelp, argc and argv); /* help & mssSetOption (opt, argc and 
argv); Setting & fpr=mssOpenFPR of /* command option 
(optINF.str,4); /* input file opening & hdi=mssReadHeader (fpr);
Reading & printf of /* header ("title: %s¢@n "and 
hdi->title); Printf ("comment: %s¢@n "and hdi->comment); 
Printf ("the version of XMLtable: %d¢@n "and hdi->version);
Printf ("the version of XML: %s¢@n "and hdi->xmlver); 
Printf ("the encoding of XML: %s¢@n "and hdi->xmlenc); 
Printf ("size of header (BYTE): %d¢@n "and hdi->datTop); 
For (i=0; I<hdi->flds->cnt; I++) {Printf (the 
item information which appears "in the %d turn eye: Item number 
=%d item name =%s sort=%d reverse=%d nu meric=%d¢@n ", i, MssFlds2num 
(as for item number inside hdi->flds and i) +1, /* being to start from
0" +1 "* MssFlds2name (hdi->flds, i), MssFlds2priority (hdi->flds, i),
MssFlds2revFlg (hdi->flds, i), MssFlds2numFlg (hdi->flds, i)); }
Printf ("¢@n"); Printf ("item number [ as for the item name of %d
] [ %s ] ¢@n",1, mssFldNum2Add (hdi->flds,0) ->name); Printf 
("item number [ as for the item name of %d ] [ %s ] ¢@n",3, 
mssFldNum2Add (hdi->flds,2) ->name); Printf ("item name [ as for
the item number of %s ] [ %d ] ¢@n" and "customer number", 
mssFldNam2Add (hdi->flds, "customer number") ->num+1); Printf 
("item name [ as for the item number of %s ] [ %d ] ¢@n", "date" and 
mssFldNam2Add (hdi->flds, "date") ->num+1); MssCloseFPR (fpr); 
Close & mssFreeHeader of /* input file (hdi); /* input 
header territory opening & mssFreeOption (opt); Opening & 
mssShowEndMsg of /* option territory (); /* completion message *
mssEnd (mssExitSuccess); /* end & return (0); /* to avoid 
warning message *}

". /readheader -ithe result of executing is sample.xt " as follows.

$ . /readheader -i sample.xt
title: Customer buying quantity amount comment 
classified by day: Version of XMLtable sample data XMLtable: 
The version of 11 XML: 1.0 The encoding of XML: 
Size of euc-jp header (BYTE): 0 0th the item information 
which appears in: Item number =2 item name = customer name 
sort=0 reverse=0 numeric=0 1st the item information which appears in: 
Item number =1 item name = customer number sort=1 reverse=0 
numeric=0 2nd the item information which appears in: Item number
=3 item name = date sort=0 reverse=0 numeric=0 3rd the item 
information which appears in: Item number =4 item name = buying 
quantity sort=0 reverse=0 numeric=0 4th the item information which 
appears in: Item number =5 item name = buying amount sort=2 
reverse=1 numeric=1 item number [ as for item name of 1 ] [ customer 
number ] item number [ as for item name of 3 ] [ date ] item name [ as
for item number of customer number ] [ 1 ] item name [ as for item 
number of date ] [ 3 ] #END# 1051 2003/08/02 16:10:26 ". /readheader 
-i sample.xt" in=0 out=0 $
[an error occurred while processing this directive]