xml属性中“本地名称”和“限定名称”之间的差异

你能帮我理解一下xml属性中’local name’和’qualified name’之间的区别吗? 来自http://developer.android.com/reference/org/xml/sax/Attributes.html :

/** Look up an attribute's local name by index. */ abstract String getLocalName(int index) /** Look up an attribute's XML qualified (prefixed) name by index. */ abstract String getQName(int index) 

在这个例子中,

   

有什么区别?

限定名称包括名称空间前缀和本地名称foo:att2foo:att2

示例XML

  

Java代码:

ATT1

没有名称空间前缀的属性不会选择默认名称空间。 这意味着虽然root元素的命名空间是"http://www.example.com/DEFAULT" ,但att1属性的命名空间是""

 int att1Index = attributes.getIndex("", "att1"); attributes.getLocalName(att1Index); // returns "att1" attributes.getQName(att1Index); // returns "att1" attributes.getURI(att1Index); // returns "" 

ATT2

 int att2Index = attributes.getIndex("http://www.example.com/FOO", "att2"); attributes.getLocalName(att2Index); // returns "att2" attributes.getQName(att2Index); // returns "foo:att2" attributes.getURI(att2Index); // returns "http://www.example.com/FOO" 

本地名称是不受命名空间限定的名称。 完全限定的名称包括命名空间(如果有)。

可能值得阅读有关XML名称的W3C建议以获取完整的详细信息。

基本上,如果您的XML文件中没有xmlns ,则可能不需要担心名称空间。 如果你有命名空间,你可能想要在检查元素名称等时创建一个完全限定的名称。

请注意,根据我的经验,属性通常不太可能使用名称空间而不是元素。