D
D
DarkByte20152017-08-30 23:33:58
Java
DarkByte2015, 2017-08-30 23:33:58

Parsing non-standard xml?

I want to parse an apache file:

<VirtualHost *:80>
  # The ServerName directive sets the request scheme, hostname and port that
  # the server uses to identify itself. This is used when creating
  # redirection URLs. In the context of virtual hosts, the ServerName
  # specifies what hostname must appear in the request's Host: header to
  # match this virtual host. For the default virtual host (this file) this
  # value is not decisive as it is used as a last resort host regardless.
  # However, you must set it for any further virtual host explicitly.
  #ServerName www.example.com

  ServerAdmin [email protected]
  DocumentRoot /var/www/html

  # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
  # error, crit, alert, emerg.
  # It is also possible to configure the loglevel for particular
  # modules, e.g.
  #LogLevel info ssl:warn

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  # For most configuration files from conf-available/, which are
  # enabled or disabled at a global level, it is possible to
  # include a line for only one particular virtual host. For example the
  # following line enables the CGI configuration for this host only
  # after it has been globally disabled with "a2disconf".
  #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Accordingly, both for reading and for writing. How realistic is this and how to turn it around? The format is very similar to xml, but still it is clear that this is not entirely true. Is it possible to somehow adapt the usual libraries to work with xml? Or maybe for the Apache format there is some kind of own liba? Or I xs, write my parser from scratch? Or to be sophisticated with regexes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Semchenko, 2017-08-31
@0xcffaedfe

Google "httpd-vhosts.conf parser" is full of solutions.

A
Alexey Cheremisin, 2017-08-31
@leahch

Ordinary libraries for XML will not work, and libraries for "broken" html will not work either. Since the Apache config differs from both, and very much.
See if this fits? https://github.com/jrossi227/ApacheConfParser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question