# xml2env

## Description

`xml2env` is a tool to convert the resource data for the ENV library written in XML format to the source file format in C.

## Using the Library

### Start Command

    % perl init2env.pl RESOURCE_FILE
    [-o OUTPUT_FILE]

The resource data written in the INIT format specified by `RESOURCE_FILE` is changed to the C source file format and is output with the name `RESOURCE_FILE.result.c`.
However, it is necessary to put in the absolute path of files you want to change in `RESOURCE_FILE`.

With the `-o` option, the output file name can be changed from `RESOURCE_FILE.result.c` to `OUTPUT_FILE`.

Note: If in an environment where XML::Parser cannot be used, it is necessary to include the latest version of perl and the expat library in the cygwin setup.

Description example of the resource data for the ENV library in XML format.

XML formatted resource data before being changed.

> `&ltenvlist>
> &ltresource name="environment1">
> &ltclass name="myClass11">
> &ltstring name="str1"&gtmario</string>
> &lthexbinary name="bin1"&gt12345678</hexbinary>
> </class>
> </resource>
> &ltresource name="environment2">
> &ltclass name="myClass21">
> &ltstring name="str1"&gtmario</string>
> &lthexbinary name="bin1"&gtabcd123</hexbinary>
> &lthexbinary name="bin2" src="../test/test.txt"/>
> </class>
> &ltclass name="myClass22">
> &lts32 name="data1"&gt-500</s32>
> &ltu16 name="data2"&gt0x8000</u16>
> </class>
> </resource>
> </envlist>`

C Source File formatted Resource Data after being changed.

> `ENVResource myResource1[] = {
> "myClass11.str1", ENV_STRING( "mario" ),
> "myClass11.bin1", ENV_BINARY( "\x31\x32\x33\x34\x35\x36\x37\x38" ),
> ENV_RESOUCE_END
> };
> ENVResource myResource2[] = {
> "myClass21.str1", ENV_STRING( "mario" ),
> "myClass21.bin1", ENV_BINARY( "file contents" ),
> "myClass21.bin2", ENV_BINARY( "test.txt file contents" ),
> "myClass22.data1", ENV_S32( -500 ),
> "myClass22.data2", ENV_U16( 0x8000 ),
> ENV_RESOUCE_END
> };
> ENVResource* resourceArray[]={ myResource1, myResource2, NULL };`

When the resource type is BINARY, it is possible to make the file contents into element data automatically by surrounding the reletive file path within the src attribute inside the element with`""` .

Resource data can be used as is by compiling the generated C source file and the program using ENV together.

## Location

`$NitroSDK/tools/bin/xml2env.pl`

## See Also

`ENV`

## Revision History

10/20/2005 Initial version.