Quoting Terry Brown: > Hi, new to generateDS and wondering if it can help with this. I want > to develop an XML authoring system which shows the user a list of valid > options based on an XML Schema. > > I've done this once before, long ago, used XSLT to translate the XSD to > an XML "template" that a PHP web app. used to offer the user valid > choices for adding elements etc. The speed was marginal, so I > translated the whole thing to C++, which was no faster :-} > > This time my from scratch approach would be to use Python / lxml to > generate a JSON serializable data structure for the "template", and > Python / Django for the app. interface. > > But I'm wondering if generateDS or some of its components can handle > the XSD -> "template" step. The member_data_items_ member is a step in > the right direction, but doesn't have enough detail for min/maxOccurs, > choice vs. sequence etc. etc. > > Is there a point where I can tap in to generateDS to answer the > question: at node /some/node/path the valid attributes are ... and the > valid elements are ...? With min/maxOccurs and other structure / > constraint info. available.
Terry, The kind of data mining task that you describe might be a complex kind of thing to do with data bindings (classes) generated by generateDS.py. You'd still have the problem of searching though the tree to find the class you are looking for. I've just recently been working on an extension to generateDS.py itself that required a similar kind of search of an XML schema. With the xpath capability in lxml, that seemed pretty easy. So, for example, here is a small bit of code that searches for a complexType with a specific name, and then retrieves all the attributes defined in that complexType: from lxml import etree def test(infilename, typename): root = etree.parse(infilename).getroot() ns = {root.prefix: root.nsmap[root.prefix]} pat = './/xs:complexType[@name="%s"]' % (typename, ) t1 = root.xpath(pat, namespaces=ns)[0] attributes = t1.xpath('./xs:attribute', namespaces=ns) for attribute_node in attributes: # do something with each attribute node. attr_name = attribute_node.get('name') attr_type = attribute_node.get('type') print 'attribute -- name: "%s" type: %s' % (attr_name, attr_type, ) test('my_schema.xsd', typename="someDefinedType") If I understand your need correctly, some of it at least seems quite easy to do with lxml and xpath, as, perhaps, the above sample code shows. Hope this helps. But, you are right. I certainly should experiment some with generating data bindings from the XML schema that defines XML schema itself. If I learn more about that, I'll let you know. Dave -- Dave Kuhlman http://www.davekuhlman.org ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk _______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users