Differences between a 'local name' and 'qualified name' in a xml attribute

后端 未结 2 637
感情败类
感情败类 2021-02-13 12:35

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/sa

2条回答
  •  无人共我
    2021-02-13 13:40

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

    Sample XML

    
    

    Java Code:

    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

    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"
    

提交回复
热议问题