Opened 11 years ago

Closed 6 years ago

#576 closed new feature (wontfix)

flexible parsing engine (XML-based) with pluggable replacement rules

Reported by: lemon-head Owned by:
Priority: major Milestone: unassigned
Component: FrameWork Keywords:


This can be a cool thing to use in many contexts:

  • bbcode parsing for forum posts or other user text
  • using special xml tags for translations

How to build an XML parser with PHP

The answer is: We don't make a new one, we use one of the existing options:

Both of them read the input, and construct a DOM tree, that we can manipulate.

How can we plug replacement rules into the parser ?

Simple as that:

  • The parser has a replacement table for all kinds of xml tags. This table is simply an associative array, mapping tag names (string) to replacement functions (php callback).
  • The parser runs recursively on the DOM tree, and for each node it checks if the tag name is found in the replacement table. If yes, it calls the replacement callback, with arguments being the node, and the document.
  • An alternative would be to make a subclass of the parsing engine, and define a method "replace_$tagname($dom_node)" for each tag name to replace.

How can we use an XML parser for BBCode ?

I don't promise that it works in any case, but the general idea is like this:

  • replace [] with <>, and vice versa
  • run the parser
  • replace <> with [], and vice versa

Change History (2)

comment:1 Changed 7 years ago by jsfan

  • Milestone Future deleted

Milestone Future deleted

comment:2 Changed 6 years ago by guaka

  • Milestone set to unassigned
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.