Java saxparser: different from ‘localname’ and ‘QName’`

In Java, the handler class contains a method named startelement The this method has a prototype:

Public void startelement (string URI, string localname, string QName, attributes attribute)

I have read the Oracle Java website, but I still don't understand the difference between localname and QName parameters They explained:

In the above definition, I don't know some concepts: prefix (what prefix?) Namespace

Who can explain (as simple as possible) about these parameters for me

Thank you:)

Solution

For example, I will refer to the following XML example:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="note">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="to" type="xs:string"/>
        <xs:element name="from" type="xs:string"/>
        <xs:element name="heading" type="xs:string"/>
        <xs:element name="body" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Namespace

A namespace is a logical container for defining elements XML schema namespace with URI: http://www.w3.org/2001/XMLSchema )In the above document, it is being referenced on line 2 XML document processing may use XML parser, which may be namespace aware, but documents using namespace usually need to be parsed by namespace aware parser

Define namespaces so that a) they can be cataloged by the parser, and b) so that elements with the same name in different namespaces can exist in the same document without becoming ambiguous

Prefix

A prefix is a short key used to reference a namespace In the above example, XS is used to reference the XML schema namespace

Local name (partial)

Elements in the document have names defined in namespaces In the above example, you can find schema, element, complexType, sequence and element as local names If your document references multiple namespaces and one or more of these namespaces define elements with the same name, the local name may be ambiguous

Qualified name (QName)

A qualified name consists of a namespace prefix (optionally, some implementations can use a namespace URI), followed by a:, followed by the local name of the element In the above example, you can find XS: schema, XS: element, XS: complexType, XS: sequence and XS: element as qualified names These names are unambiguous and can be processed and verified by the parser

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>