[XML-SIG] need help with removeChild()
narendar rao
narendar.n at gmail.com
Wed Feb 18 21:07:27 CET 2009
Hi,
I am newbie to Python and trying to edit a XML file.
I am attaching the XML file.
I am trying to remove the Node which has a certain attribute value.
For example, I want to remove <c> Node after checking if the attribute
value(Name) equals to the command line parameter passed.
In the removeConfiguration, i want to iterate over the nodes and check
for attribute value and then remove child.
If we use removeChild(), will it save changes to the file that we are
editing. If it doesn't, can some one show me how to do that.
Can some one help me in writing this code? It will help me in
understanding some of the things alot.
Thanks,
Narender
-------------- next part --------------
import os,sys
from xml.dom import minidom
def Usage():
print "\n Usage: '%s' Folder location Attribute value"
print "\n Example: '%s' G:\test write"
sys.exit(1)
def CheckArgs():
if len (sys.argv) < 3:
Usage()
sys.exit(-1)
def RemoveConfiguration(file,doc,sSrcAttribute):
node = doc.childNodes[0]
def callBack(ctx,root,files):
for file in files:
file = root + "\\" + file
if not file.lower().endswith('.xml'):
continue
try:
print file
doc = minidom.parse(file)
RemoveConfiguration(file,doc,u'Name')
except:
print "Error in Processing"
CheckArgs()
sSrcFolder = sys.argv[1]
sSrcAttribute = sys.argv[2]
os.path.walk(sSrcFolder,callBack,0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xmlfile.xml
Type: text/xml
Size: 119 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/xml-sig/attachments/20090218/d6ec85a4/attachment.bin>
More information about the XML-SIG
mailing list