2012-08-31 70 views
1

我的代码显示android操作系统的xml。Android命名空间lxml python

我需要显示

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

我试图

ET.Element("{http://schemas.android.com/apk/res/android}name") 

,但它显示

<ns0:name xmlns:ns0="http://schemas.android.com/apk/res/android"> 

能有人给我一个片段如何解决呢?

+0

您确定命名空间前缀在这里确实很重要吗?对于大多数XML处理来说,他们不会:在内容中处理QNames几乎是唯一不是这种情况的地方。 –

回答

2

如果你真的要提供一个命名空间映射(映射前缀命名空间URI)时创建的元素,像这样:

nsmap = {"android", "http://schemas.android.com/apk/res/android}name"} 
elem = ET.Element("{http://schemas.android.com/apk/res/android}name", nsmap=nsmap) 

或全球注册的前缀映射,使“Android”的前缀将在创建该名称空间中的元素时自动使用:

ET.register_namespace("android", "http://schemas.android.com/apk/res/android") 
+0

我得''爱'xml ... – n611x007

+0

第二个是我的代码很好用!谢谢! – DomonLee