how to keep the xml-stylesheet?



I want to keep the xml-stylesheet. But it doesn't work. i use python to modify the xml for deploy hadoop automaticly


XML:



<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
    <name>fs.default.name</name>
    <value>http://hdfsc11:9000</value>
  </property>
</configuration>


Code:



from xml.etree.ElementTree import ElementTree as ET

def modify_core_site(namenode_hostname):
tree = ET()
tree.parse("pkg/core-site.xml")
root = tree.getroot()
for p in root.iter("property"):
name = p.find("name").text
if name == "fs.default.name":
text = "hdfs://%s:9000" % namenode_hostname
p.find("value").text = text
tree.write("pkg/tmp.xml", encoding="utf-8", xml_declaration=True)

modify_core_site("c80")


Result:



<?xml version='1.0' encoding='utf-8'?>
<configuration>
<property>
    <name>fs.default.name</name>
    <value>http://hdfsc80:9000</value>
  </property>
</configuration>


The xml-stylesheet disappear... How can i keep this?


No comments:

Post a Comment