CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 11-23-2010, 04:12 AM   #1
sauzer
Veteran
portfolio
Carlo Sansonetti
Senior Character TD
Los Angeles, USA
 
Join Date: Dec 2003
Posts: 58
python-xml headache

So I can't figure this out! I have been looking at this code for hours and I cannot find anything wrong with it. I went on several sites, did research and looked at my python xml book, but I think I am doing everything right.... however I know there is something wrong otherwise there would be no error

this is the code I am writing:

def removeCurve(curveName):
"""Removes a curve node from the XML file"""
if os.path.getsize(xmlFile) > 0 :
doc = parse(xmlFile)
if curveElementExists(curveName) != 0:
root = doc.documentElement
print root.nodeName
curveEl=findCurveElement(curveName)

if curveEl !=0:
root.removeChild(curveEl)
writeCurveFile(doc)
return curveEl
else:
raise NameError('There is no curve OBJECT named "%s" in the XML file' % curveName)
raise NameError('There is no curve named "%s"' % curveName)

This is the error I get;
# line 164 of file C:\Program Files\Autodesk\Maya2010\bin\python26.zip\xml\dom\m inidom.py in module removeChild
# raise xml.dom.NotFoundErr() #

Can anybody help?

Thanks!
 
Old 11-23-2010, 08:36 AM   #2
ewerybody
wt
 
ewerybody's Avatar
portfolio
eRiC Werner
pyroTechnical Artist
Berlin, Germany
 
Join Date: Jun 2003
Posts: 613
what xml module are you using?
what is findCurveElement? what does it return? does it work if you use the return manually?
__________________
goodsoul.de
 
Old 11-23-2010, 08:42 AM   #3
sauzer
Veteran
portfolio
Carlo Sansonetti
Senior Character TD
Los Angeles, USA
 
Join Date: Dec 2003
Posts: 58
This is what I am importing:
import xml.dom.minidom as xmlDom
from xml.dom.minidom import parse

The findCurveElement(curveName) function does work by itself. I have tested several times, so I am pretty sure.
 
Old 11-23-2010, 09:45 AM   #4
ewerybody
wt
 
ewerybody's Avatar
portfolio
eRiC Werner
pyroTechnical Artist
Berlin, Germany
 
Join Date: Jun 2003
Posts: 613
and what does findCurveElement return? If it does not find a thing what comes out of it? Is it really 0 like you check for? Or is it maybe "" empty string or is it even a None?
I had several of that cases:
Code:
if variable is not None:
__________________
goodsoul.de
 
Old 11-23-2010, 05:38 PM   #5
sauzer
Veteran
portfolio
Carlo Sansonetti
Senior Character TD
Los Angeles, USA
 
Join Date: Dec 2003
Posts: 58
This is the code for findCurveElement:

def findCurveElement(curveName):
"""If the passed curve exists in the XML document, then it returns the
curve node OBJECT. If it cannot find it then returns the value '0'"""
doc = parse(xmlFile)
root = doc.documentElement
curvesList = root.getElementsByTagName('curveShape')
for curve in curvesList:
if curve.getAttribute('name') == curveName:
return curve
return 0

and this is what I get if I print the return of findCurveElement:
<DOM Element: curveShape at 0x1b475788>

which is what I would expect
 
Old 11-23-2010, 10:57 PM   #6
ewerybody
wt
 
ewerybody's Avatar
portfolio
eRiC Werner
pyroTechnical Artist
Berlin, Germany
 
Join Date: Jun 2003
Posts: 613
can you attach an example xml where it does not work as well?
__________________
goodsoul.de
 
Old 11-23-2010, 11:17 PM   #7
sauzer
Veteran
portfolio
Carlo Sansonetti
Senior Character TD
Los Angeles, USA
 
Join Date: Dec 2003
Posts: 58
<curveShapesList>
<curveShape name="circle">
<code codeString="some code" orientation="ZY"/>
</curveShape>
 
Old 11-27-2010, 09:39 AM   #8
Pyrokinesis
Frequenter
portfolio
Shaun Friedberg
Technical Director
Weta Digital
Wellington, NZ
 
Join Date: May 2006
Posts: 268
Hey sauzer,
Sorry no offense, but I'm a little confused by reading your post, I cant figure out what you are trying to do... So I'll just give some blanket advice and hope its useful.

Your xml is formatted poorly and causing errors, heres a cleaner example:

Code:
<?xml version="1.0" encoding="UTF-8"?> <curveShapesList> <curveShape name="circle1" codeString="code goes here" orientation="ZY"/> <curveShape name="circle2" codeString="code goes here" orientation="ZY"/> </curveShapesList>


Notice the header, I think your example was also missing a closing curveShapesList node.
ElementTree or cElementTree is much faster and easier to read than dom.

simple example:

Code:
from xml.etree import ElementTree as elementTree xmlPath = '/path/to/your/xmlExample.xml' xmlRoot = elementTree.parse(xmlPath).getroot() curveShapes = xmlRoot.findall('curveShape') if curveShapes: for curveShape in curveShapes: name = curveShape.get('name') orientation = curveShape.get('orientation') codeString = curveShape.get('codeString')

Deleting is as simple as:
del curveShape

Again I'm not sure exactly what your end goal is, I hope this helps.

Good Luck.
__________________
Ok, But Can You Do It...ON FIRE!
 
Old 11-27-2010, 09:39 AM   #9
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:15 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.