Do input template languages exist?

Posted by marczellm on Programmers See other posts from Programmers or by marczellm
Published on 2014-05-30T07:09:29Z Indexed on 2014/05/30 9:36 UTC
Read the original article Hit count: 172

Filed under:

When I have to create some textual representation of data, I can use a template language, so that my code does not have to worry about the structure of the output file - I can sometimes even write code that's independent of whether the output is XML, LaTeX or any other plain text. A simple example:

Template (in separate file):

<someXmlTag>
$variableName
</someXmlTag>

Code:

Template(temstring).substitute(variableName="value")

Result (written to output file):

<someXmlTag>
value
</someXmlTag>

I want to do the same, but in the opposite direction. I have XML or plain text or whatever files to input. I want to describe the input structure in a separate file that looks like the input but has these variable declarations in it, and I want to handle it with code that's independent of the structure.

Is there a library for this concept?

(We usually handle XML input by using an XML parser library to describe the input structure in program code, handle plaintext input by writing regexes in code, and don't handle LaTeX input because LaTeX can't really be parsed.)

© Programmers or respective owner

Related posts about templates