A
Asun Friere
Now that PyXML (and thus xmlproc) is defunct, does anyone know any
handy modules (apart from re for parsing DTDs?
handy modules (apart from re for parsing DTDs?
Am 10.11.2010 03:44, schrieb Felipe Bastos Nunes:
Don't repeat the mistakes of others and use XML as a configuration
language. XML isn't meant to be edited by humans.
can point me in the way of a simple DTD parser, that is.xsd conversion script and then simply use HTMLParser. Unless someone
Back to the initial question: I highly recommend LXML for any kind of
XML processing, validation, XPath etc.
Sorry Christian, didn't realise at first that that was a response to
MY intial question. But does lxml actually have something for parsing
DTDs, as opposed parsing XML and validating it against a DTD?
What's your interest in parsing a DTD if you're not up to validating XML?
What's your interest in parsing a DTD if you're not up to validating XML?
Spitting out boilerplate code.
[...]
A few years back I used a similar technique to write some boiler plate
python code where xml was isomorphically represented on a class per
element basis (which will no doubt offend some people's sense of
generalisation, but is none the less an interesting way to work with
XML).
<snippetysnip>Yes but configuration files are not necessarily meant to be edited by
humans either!
Having said that, I'm actually old school and prefer "setting=value"
human editable config files which are easily read into a dict via some
code something like this:
Me too when possible, TBH if I only needed strings and there was no
pressing security issue I'd just do this...
config = {}
for line in (open("config.txt", 'r')):
if len(line) > 0 and line[0] <> "#":
param, value = line.rstrip().split("=",1)
config[param] = value
Me too when possible, TBH if I only needed strings and there was no
pressing security issue I'd just do this...
config = {}
for line in (open("config.txt", 'r')):
if len(line) > 0 and line[0] <> "#":
param, value = line.rstrip().split("=",1)
config[param] = value
That's five whole lines of code. Why go to all that trouble when you can
just do this:
import config
Give lxml.objectify a try. It doesn't use DTDs, but does what you want.
It's generally a good idea to state what you want to achieve, rather than
just describing the failure of an intermediate step of one possible path
towards your hidden goal. This list has a huge history of finding shortcuts
that the OPs didn't think of.
That's five whole lines of code. Why go to all that trouble when you
can just do this:
import config
I kid, but only partially.
2010/11/10 said:Me too when possible, TBH if I only needed strings and there was no
pressing security issue I'd just do this...
config = {}
for line in (open("config.txt", 'r')):
if len(line) > 0 and line[0] <> "#":
param, value = line.rstrip().split("=",1)
config[param] = value
That's five whole lines of code. Why go to all that trouble when you
can just do this:
import config
I kid, but only partially. Where this really shines is when you're
prototyping something and you need to configure complex object
hierarchies. No need to spend time writing parsers to generate the
hierarchies; you just construct the objects directly in the config.
When the project becomes mature enough that configuration security is a
concern, then you can replace the config with XML or whatever, and in
the meantime you can focus on more important things, like the actual
project.
Cheers,
Ian
Heh, mainly because I figure the config module will have a lot more
options than I have use for right now and therefore the docs will take
me longer to read than I will save by not just typing in the above
Does any, libxml2 or lxml, collect children like jdom does in java?
List<Element> children = myRoot.getChildren();
Christian said:Don't repeat the mistakes of others and use XML as a configuration
language. XML isn't meant to be edited by humans.
Christian said:I'm sorry but every time I read XML and configuration in one sentence, I
see the horror of TomCat or Shibboleth XML configs popping up.
Ian Kelly said:config = {}
for line in (open("config.txt", 'r')):
if len(line) > 0 and line[0] <> "#":
param, value = line.rstrip().split("=",1)
config[param] = value
That's five whole lines of code. Why go to all that trouble when you
can just do this:
import config
[...]Not a good idea.Ian Kelly said:On 11/9/2010 11:14 PM, r0g wrote:
config = {}
for line in (open("config.txt", 'r')):
if len(line) > 0 and line[0] <> "#":
param, value = line.rstrip().split("=",1)
config[param] = value
That's five whole lines of code. Why go to all that trouble when you
can just do this:
import config
I think you misunderstand me. There is no config module and there are
no docs to read. It's just the configuration file itself written as a
Python script, containing arbitrary settings like:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.