python中创建xml文件用libxml 2和xm.dom哪个简单些

"jinyan" <[email protected]> Tue, 22 Jan 2008 17:43:16 +0800
Newsgroups gmane.comp.python.chinese
Message-ID <[email protected]>
我是pyhton新手,目前要实现一个自动创建虚拟机的配置文件(xml格式的)昨天看了
下xm.dom的一个例子,创建一个xml文件好像很复杂,一个同学说可以考虑下libxml2
库。

刚看了下有几千行代码,头都大了。虚拟机的xml配置文件如下:

<domain type='xen' id='3'>

  <name>fv0</name>

  <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid>

  <os>

    <type>hvm</type>

    <loader>/usr/lib/xen/boot/hvmloader</loader>

    <boot dev='hd'/>

  </os>

  <memory>524288</memory>

  <vcpu>1</vcpu>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>restart</on_crash>

  <features>

     <pae/>

     <acpi/>

     <apic/>

  </features>

  <clock sync="localtime"/>

  <devices>

    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>

    <interface type='bridge'>

      <source bridge='xenbr0'/>

      <mac address='00:16:3e:5d:c7:9e'/>

      <script path='vif-bridge'/>

    </interface>

    <disk type='file'>

      <source file='/root/fv0'/>

      <target dev='hda'/>

    </disk>

    <disk type='file' device='cdrom'>

      <source file='/root/fc5-x86_64-boot.iso'/>

      <target dev='hdc'/>

      <readonly/>

    </disk>

    <disk type='file' device='floppy'>

      <source file='/root/fd.img'/>

      <target dev='fda'/>

    </disk>

    <graphics type='vnc' port='5904'/>

  </devices>

</domain>

要实现一个这样的配置文件,里面的内容要能动态修改,应该是传参数进去再生成。

请教下高手,我用这两个库中的任意一个该怎样实现,或者有甚么其它的方法。我只有
一周时间了,谢谢啊!

_______________________________________________
python-chinese
Post: send [email protected]
Subscribe: send subscribe to [email protected]
Unsubscribe: send unsubscribe to  [email protected]
Detail Info: http://python.cn/mailman/listinfo/python-chinese