xml属性中“本地名称”和“限定名称”之间的差异 [英] Differences between a 'local name' and 'qualified name' in a xml attribute

查看:577
本文介绍了xml属性中“本地名称”和“限定名称”之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否帮我理解xml属性中本地名称和限定名称之间的区别?
来自 http://developer.android.com/reference/ org / xml / sax / Attributes.html

Can you please help me understand what is the difference between 'local name' and 'qualified name' in a xml attribute? From 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)

在此示例中,

<anelement attr1="test" attr2="test2"> </anelement>

有什么区别?

推荐答案

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

The qualified name includes both the namespace prefix and the local name: att1 and foo:att2.

示例XML

<root 
    xmlns="http://www.example.com/DEFAULT" 
    att1="Hello" 
    xmlns:foo="http://www.example.com/FOO" 
    foo:att2="World"/>

Java代码:

att1

att1

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

Attributes without a namespace prefix do not pick up the default namespace. This means while the namespace for the root element is "http://www.example.com/DEFAULT", the namespace for the att1 attribute is "".

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

att2

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属性中“本地名称”和“限定名称”之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆