I also hear lxml is the fastest, if you end up testing different xml libraries.
On Aug 27, 2012, at 10:45 PM, Jay Goodman <[email protected]> wrote: > I agree with the JSON route. It has a lot less overhead to deal with, and > you don't have to deal with everything being converted to strings. If you are > stuck with xml though, I really like cElementTree because it is fast: > http://effbot.org/zone/celementtree.htm > > > On Saturday, August 25, 2012 12:56:44 AM UTC+8, Justin Israel wrote: > There is a pretty simple looking minidom example here: > http://www.postneo.com/projects/pyxml/ > Shows you just about all you will need to accomplish the exporting of > the values.You will probably end up doing something very similar to > this, using a bunch of createElement() calls, and setting attributes > on them like: > > ### > from xml.dom.minidom import Document > > doc = Document() > > root = doc.createElement("nodes") > doc.appendChild(root) > > node = doc.createElement("node1") > node.setAttribute("path", "|foo|bar") > root.appendChild(node) > > attr = doc.createElement("attrib") > attr.setAttribute("name", "tx") > attr.setAttribute("type", "float") > val = doc.createTextNode("10.5") > attr.appendChild(val) > node.appendChild(attr) > > attr = doc.createElement("attrib") > attr.setAttribute("name", "visibility") > attr.setAttribute("type", "int") > val = doc.createTextNode("0") > attr.appendChild(val) > node.appendChild(attr) > > print doc.toprettyxml(indent=" ") > ### > > Which will create: > > <?xml version="1.0" ?> > <nodes> > <node1 path="|foo|bar"> > <attrib name="tx" type="float"> > 10.5 > </attrib> > <attrib name="visibility" type="int"> > 0 > </attrib> > </node1> > </nodes> > > > There are even packages our there to help you automatically serialize > python objects to xml. But honestly though, if you aren't bound to > XML, then JSON would be a whole lot better for storing data types. > XML doesn't natively support any concept of data types, which means > you have to parse them back out to the correct type yourself, based on > the xml tags, or by doing an eval on them to test the types. JSON > would simple be like this: > > import json > > d = { > '|foo|bar': { > 'tx': 10.5, > 'visibility': 0 > } > } > > j = json.dumps(d, indent=4) > print j > > And looks like: > > { > "|foo|bar": { > "visibility": 0, > "tx": 10.5 > } > } > > > > > > On Fri, Aug 24, 2012 at 6:03 AM, 5inch <[email protected]> wrote: > > > > Hi Folks, > > > > has anyone of you experience with > > Python´s xml.dom.minidom and Maya. > > > > I want to export some Maya Attributes (Int,String,Float) > > via Python in a XML-File. > > I didn´t find any good howTo/Tutorial on the Web which explains me all the > > syntax in a > > Dummie-fashion-way. > > > > Thanks for any Links/help, > > > > Cheers, 5inch > > > > -- > > view archives: http://groups.google.com/group/python_inside_maya > > change your subscription settings: > > http://groups.google.com/group/python_inside_maya/subscribe > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
