Git Product home page Git Product logo

txt2xml's Introduction

### Description

txt2xml converts indented text data to xml.

The purpose of txt2xml is to make it possible to edit data in a simplified and editor, both human and text, friendly way while without incurring any conversion cost.

In my particular case, I use [GSL] (http://github.com/imatix/gsl) for code generation, schema construction, state machine, etc but I don't particular like editing XML so this tool allows me to have the best of both worlds.

### Format

The format consists of lines text representing xml tags and attributes where each line is indented to denote hierarchical placement.

The format looks quite similarly to well formatted XML, but without brackets, end tags and most xml quoting.

A line consists of tag name followed by any number of attribute name value pairs.

Each attribute name value pair can be optionally separated by an equal sign (=). Single word attribute values do not need to be quoted, while multi word attributes must be quoted, either with single or double quotes. Quotes inside attributes can be escaped with a backslash. If an attribute name or value has an equal sign in it the name or value can be quoted or the equal sign escaped with a backslash.

The input is expected to have a single root, just like XML. In any case, the produced results reflects the input structure.

Lines that begin with one or more octothorpes (#) are parsed and output as comments.

If every XML element has a common tag name, it can be omitted from the text and added back upon XML generation.

A common attribute can be similarly added as well.

Here is an example format from (examples/state-machine.txt) that omits the 'name' attribute since it is common to all elements.

machine Turnstile
  state Locked
      event coin
          action "set Unlocked"
      event pass
          action "sound alarm"

  state Unlocked
      event coin
          action "refund coin"
      event pass
          action "set Locked"
### Usage
Usage: ./txt2xml [-tag=TAG] [attribute=ATTRIBUTE] [FILE]
Converts text read from FILE(s), or standard input, to XML.
-t --tag TAG       Use TAG as element tag for each element.
-a --attribute     Use ATTRIBUTE as the first attribute for each element.
-h -? --help       Show this help output.

With no FILE, reads standard input.
Report bugs to [email protected].
### Usage Example

The command

txt2xml --attribute name examples/state-machine.txt

Generates the corresponding xml for the file and adds the missing attribute name as seen in the output:

<machine name = "Turnstile">
  <state name = "Locked">
      <event name = "coin">
          <action name = "set Unlocked"/>
      </event>
      <event name = "pass">
          <action name = "sound alarm"/>
      </event>
  </state>
  <state name = "Unlocked">
      <event name = "coin">
          <action name = "refund coin"/>
      </event>
      <event name = "pass">
          <action name = "set Locked"/>
      </event>
  </state>
</machine>
### Installation

txt2xml can be installed using the make install command or by copying the script to your favorite path location. By default, make install acts like make DESTDIR=/usr/local/bin install. Specify DESTDIR, with a different value if desired.

### Dependencies

txt2xml is a Perl program and requires the perl interpreter. There are no unusual construct so the code should run fine on most extant versions of perl.

If you want to hack on the code, you'll need to install [GSL] (imatix/gsl) in order to add tests and [gitdown] (/imatix/gitdown) in order to generate documentation in markdown format.

### Future Work

I think it would be useful to specify the --tag command in a more discriminating manner. Either by specifying a path '/a/b/c' to to which the command will be applied or specifying an exclusion set of tags {a, b, c} to which the command will not apply.

Also, useful is the ability to add text. This would be simple to implement as a here doc.

tag attr1 value1 <<TEXT
Text content line 1
Text content line 2
TEXT
### Author

This tool is written and maintained by Gyepi Sam [email protected]. Please send suggestions or bug reports.

txt2xml's People

Contributors

gyepisam avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.