June 2000
Intermediate to advanced
556 pages
8h 45m
English
We now have all the bits and pieces we need to add a tree-driven XML processing mode to xGrep. The bulk of the code changes are in the new function XMLGrepTree.
CD-ROM reference=9033.txt # XML-aware grepping using event source--either xmln or xmlv # depending on VALIDATE option. def XMLGrepTree (filename,pattern,options,out,context=""): if options & VALIDATE: # Use xmlv as a PYX event source. f = os.popen ("xmlv %s" % filename) else: # Use xmln as a PYX event source. f = os.popen ("xmln %s" % filename) # Create an empty tree. tree = xTree() tree.PYX2xTree(f) f.close() Pattern = re.compile (pattern) if options & MARK_HITS: StartOfHit = "[" EndOfHit = "]" else: StartOfHit = "" EndOfHit = "" NodeList = pyx.Descendants(tree.Root()) ...Read now
Unlock full access