Transforming an XML Document Using _Document Methods : XML Transform : XML PYTHON examples


PYTHON examples » XML » XML Transform »

 

Transforming an XML Document Using _Document Methods


 
import sys
from xml.dom.ext import PrettyPrint
from xml.dom import minidom

doc = minidom.parse(open(sys.argv[1]))

for n in doc.getElementsByTagName("ingredients"):
    n.tagName = "ingredientlist"

for n in doc.getElementsByTagName("item"):
    n.tagName = "ingredient"
    attr = n.getAttribute("num")
    n.setAttribute("quantity",attr)
    n.removeAttribute("num")

PrettyPrint(doc)

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo XML
» XML Transform