>From: shankarlingayya hiremath >Sent: Tue, August 17, 2010 7:13:07 AM >
> Hi Dave, > > I want to use your generateDS.py script to generate the data > structure for a given xml file, > > i am new to python-xml & generateDS, can you please help me to > access the attribute values from an xml file. > Shankar - Good to hear from you. Here is a bit of code: def test(inFilename): root = parse(inFilename) person_list = root.get_person() person_count = len(person_list) print 'There are %d people in this document.' % (person_count, ) person1 = person_list[0] name = person1.get_name() print 'The name of the first person is: %s' % (name, ) > for example: from the below xml file i want to know > > 1. how many "<person>" information is there Since the <person> elements are a list, you can use len() to get a count. Whenever a child is defined wth maxOccurs="unbounded" (or maxOccurs greater than 1), the child is represented as a list. > 2. and inside this what is the vale of "<name>", "<interest>" etc You can use the getter and setter methods in the generated class to access the children and attributes of an element. So, for example, to get the name of a person, use: name = person.get_name() You will want to look at the code generated for some sample element and compare that with the definition of the element/type in the XML schema. Once you have looked at a couple of these generated classes, you will see that they are all pretty much the same and are reasonably predictable. In particular, for any attribute or child named "abc" of an element/type, the class generated for that element will contain methods get_abc() and set_abc() and, if it is a list, add_abc(). Also look at the methods export(), exportAttributes(), and exportChildren(), which give examples of accessing the I've attached a bit of a more complete example. Hope this helps. Let me know if I can be of more help. - Dave [snip] -- Dave Kuhlman http://www.rexx.com/~dkuhlman
sample.py
Description: Binary data
people_9.xsd
Description: Binary data
people_9.xml
Description: Binary data
------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________ generateds-users mailing list generateds-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/generateds-users