質問

I use XSLT to convert this:

1)

<fruit>
  <apple count="2"/>
  <banana count="3"/>
</fruit>

into this:

2)

Apple: 2
Banana: 3

Is there a library that serves as a parser for text data which allows descriptive declaration of the expected tokens (think both Extended Backus–Naur Form |EBNF| and Lex/Yacc regex-based hints) and builds an XML DOM from it?

役に立ちましたか?

解決

Is there a library that serves as a parser for text data which allows descriptive declaration of the expected tokens (think both Extended Backus–Naur Form |EBNF| and Lex/Yacc regex-based hints) and builds an XML DOM from it?

Yes. FXSL 2.0 has a function f:lr-parse() which does exactly that. This is written in pure XSLT 2.0 and implements a general (table-driven) LR-1 parser, that accepts as input an XML file containing the parse tables and a text file containing the "sentence" to be parsed.

I have used this function for a number of parsers, ranging from a toy arithmetic expressions to medium-sized -- JSON, to very large -- XPath 2.0 -- languages.

See for example this article in my blog: Transforming JSON

他のヒント

A don't think you are going to find a library in any language to achieve, directly, such a broad aim as compiling any text of any form, into XML.

Although perhaps, not exactly what you want, it may be useful to know that XSLT 2.0 can take input from text files, tokenise the character data according to some rules and output XML. For evidence see my blog entry here, which shows an XSLT 2.0 generalised solution to the problem of csv to xml conversion.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top