V
V
Viktor Vsk2014-12-06 20:31:26
HTML
Viktor Vsk, 2014-12-06 20:31:26

Is there a tool for structuring XML(HTML) based on config (json,xml...)?

There is a document:

<node>
  <title attr='header'>1</title>
  <child>2</child>
</node>

Are there tools to, for example, pass:
{
  title: '//title[@attr="header"]',
  text: '//child',
  moreText: '//child'
}

And get the desired json object, array, hash at the output?
It would seem that this is not difficult to implement, but there are a lot of cases when nesting appears. When in one place you need to get a text representation, and in another - xml / html. When the structure depends on the conditions ... Perhaps someone has already taken up this.
The task is easy to solve with house-parsers, but I would like to abstract from them. At the same time without inventing your own DSL.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2014-12-06
@viktorvsk

This is what the XSLT language is designed for.
It is itself based on XML and is a language for describing the transformations of a given XML document. The XSLT parser receives the XSLT itself and the original XML document as input. This XSLT can transform the original document as you like (there are constructions for loops, conditions, arithmetic) and generate a new document based on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question