https://github.com/curusarn/xml-config-parser
Python module that parses XML config files with defined structure
https://github.com/curusarn/xml-config-parser
python xml xml-config-parser
Last synced: 3 months ago
JSON representation
Python module that parses XML config files with defined structure
- Host: GitHub
- URL: https://github.com/curusarn/xml-config-parser
- Owner: curusarn
- License: mit
- Created: 2016-12-19T16:12:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-21T14:10:51.000Z (over 8 years ago)
- Last Synced: 2025-01-30T02:24:23.755Z (4 months ago)
- Topics: python, xml, xml-config-parser
- Language: Python
- Size: 9.77 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# xml-config-parser
Python module that parses XML config files with defined structure.## Example
Xml file:
```
Value
Value
False
WUBBA LUBA DUB-DUB
```
Python code:
```
from xmlConfigParser import XmlConfigParser# NOTE: specify config options like this
# NOTE: options with "None" as default value are required
# NOTE: sections with no required options are optional:
cfgValues = {
"basicConfig": {
"optionalOption": "default_value",
"requiredOption": None
},
"nextConfig": {
"bool": "True",
"whatever": None
},
"optionalConfigSection": {
"opt1": "def_val1",
"opt2": "def_val2"
}
}cfg = XmlConfigParser(cfgValues, "/path/to/xml/config", "basicConfig")
# HACK: you can write your custom conditions and mess with default values and their optionality\
before you run parseXmlConfig()
# if /optionalConfigSection is present: set default value for /nextConfig/whatever
if not cfg.getRoot().find("basicConfig") is None:
cfg.set("new_value", "whatever", "nextConfig")
# HACK: this makes /nextConfig/whatever optional# NOTE: parseXmlConfig will raise XmlConfigParserException if any of required options are missing
cfg.parseXmlConfig()# returns value of "whatever" from "nextConfig" section
someValue = cfg.get("whatever", "nextConfig")# converts to bool value of "bool" from "nextConfig" section
boolValue = cfg.getBool("bool", "nextConfig")# returns value of "whatever" from default section specified in constructor
someOtherValue = cfg.get("optionalOption")```
## Dependencies
`xml` python library.
You can install this dependency using `pip`