By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

minidom: find what file the element was created in?

P: 1
Hi all,

(Python 2.5 under cygwin)

I'm reading a bunch of XML files and merging them in memory - each file contains a number of packages which are to be merged:

Expand|Select|Wrap|Line Numbers
  1. for fname in gInfiles:
  2.     doc=xml.dom.minidom.parse(fname)
  3.     if gDoc is None:
  4.         gDoc=doc
  5.         gTlp=relPathQuery(gDoc,'TOP-LEVEL-PACKAGES')[0] # There shall be only one
  6.     for nPackage in relPathQuery(doc,'TOP-LEVEL-PACKAGES/PACKAGE'):
  7.         info("  - " + relPathQueryContent(nPackage,'SHORT-NAME','(unknown)').strip())
  8.         if doc!=gDoc:
  9.             gTlp.appendChild(nPackage.cloneNode(1))
  10.  
There is a lot of validation besides XML validation, which my python does, by querying the tree, and checking that the input makes sense. If it does not make sense, or if I want to emit warnings, I would like to give the user meaningful pointers into the source files. That is, I want

Expand|Select|Wrap|Line Numbers
  1. ERROR: %{problem}s at %{filename}s, line %{lineno}d.
I've crawled around the minidom and DOM python documentation but haven't seen anything that might help. I also started to look in the source of minidom.py and expatbuilder.py but it's getting rather time consuming when someone might just know this OTOH!

Anyone done this? Ta

--
Steve@phoenix ~/
$ python -V
Python 2.5.1

Steve@phoenix ~/
$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.5/site.pyc matches /usr/lib/python2.5/site.py
import site # precompiled from /usr/lib/python2.5/site.pyc
# /usr/lib/python2.5/os.pyc matches /usr/lib/python2.5/os.py
import os # precompiled from /usr/lib/python2.5/os.pyc
import posix # builtin
# /usr/lib/python2.5/posixpath.pyc matches /usr/lib/python2.5/posixpath.py
import posixpath # precompiled from /usr/lib/python2.5/posixpath.pyc
# /usr/lib/python2.5/stat.pyc matches /usr/lib/python2.5/stat.py
import stat # precompiled from /usr/lib/python2.5/stat.pyc
# /usr/lib/python2.5/UserDict.pyc matches /usr/lib/python2.5/UserDict.py
import UserDict # precompiled from /usr/lib/python2.5/UserDict.pyc
# /usr/lib/python2.5/copy_reg.pyc matches /usr/lib/python2.5/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.5/copy_reg.pyc
# /usr/lib/python2.5/types.pyc matches /usr/lib/python2.5/types.py
import types # precompiled from /usr/lib/python2.5/types.pyc
import _types # builtin
# /usr/lib/python2.5/warnings.pyc matches /usr/lib/python2.5/warnings.py
import warnings # precompiled from /usr/lib/python2.5/warnings.pyc
# /usr/lib/python2.5/linecache.pyc matches /usr/lib/python2.5/linecache.py
import linecache # precompiled from /usr/lib/python2.5/linecache.pyc
import encodings # directory /usr/lib/python2.5/encodings
# /usr/lib/python2.5/encodings/__init__.pyc matches /usr/lib/python2.5/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.5/encodings/__init__.pyc
# /usr/lib/python2.5/codecs.pyc matches /usr/lib/python2.5/codecs.py
import codecs # precompiled from /usr/lib/python2.5/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.5/encodings/aliases.pyc matches /usr/lib/python2.5/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.5/encodings/aliases.pyc
# /usr/lib/python2.5/encodings/ascii.pyc matches /usr/lib/python2.5/encodings/ascii.py
import encodings.ascii # precompiled from /usr/lib/python2.5/encodings/ascii.pyc
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib/python2.5/lib-dynload/readline.dll", 2);
import readline # dynamically loaded from /usr/lib/python2.5/lib-dynload/readline.dll
>>>
Mar 24 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.