XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Auto schema/xpath generation from doc collection

Paul M wrote:
>
> I am looking for a solution(application, ideas, designs) that would 
> return:
> 1. A listing of xpaths to elements
>
>

#!/usr/bin/python
import xml.sax, glob

class PathFinder(xml.sax.handler.ContentHandler):
    def __init__(self):
        self.paths = set()
    def startDocument(self):
        self.curPath = []
    def startElement(self, name, attributes):
        self.curPath.append(name)
        path = "/".join(self.curPath)
        self.paths.add(path)
    def endElement(self, name):
        self.curPath.pop()
pf = PathFinder()

# Adjust as appropriate for finding documents in your collection
for name in glob.glob("*.xml"):
    xml.sax.parse(name, pf)
paths = list(pf.paths)
paths.sort()
for path in paths:
    print path

-- 
Bob Kline
http://www.rksystems.com
mailto:bkline@rksystems.com



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS