[xml] Tools to look inside a DTD allows?
- From: Jack Schwartz <jack schwartz oracle com>
- To: xml gnome org
- Cc: Ethan Quach <ethan quach oracle com>
- Subject: [xml] Tools to look inside a DTD allows?
- Date: Fri, 03 Dec 2010 16:48:07 -0800
Hi everyone.
I am using python/lxml. I want to append one XML tree as a branch of
another. None of the the trees have to validate yet, but I want to
merge the subtree in the right place, so that it can validate later
(after other merges are done, for example).
If I have the following subtree:
a
/ \
b b
and want to merge it under "c" in the main tree, and "c" is declared in
the DTD as:
<!ELEMENT c (d, e, a+, f)>
I'm looking for a documented way to look into a DTD, to learn that "a"
must be added after "e" and before "f", and that at most one "a" can be
added, but haven't seen one.
The closest I've come up with is dumping the DTD with the following
python program:
- - -
from libxml2 import parseDTD
outfile = open("/tmp/dtd.out", "w")
dtd = parseDTD(None, "dtdfile.dtd")
dtd.debugDumpDTD(outfile)
- - -
The output shows what I need: the names, order and quantity of different
children per parent element. However, I am reliant on an undocumented
output format, which could change and which would break my code if it did.
Another approach would be to just look at the original DTD, searching
for "<!ELEMENT" lines.
However, it would be better if I used a tool to get this information if
one existed. (In my simple case, at least it would help with skipping
comments in the DTD file, etc.) Does such a tool or API exist in
libxml2, lxml or somewhere else?
Thanks very much,
Jack
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]