Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

html - Is it possible to have multiple namespace prefixes in XML?

I would like to do something like this:

<root:secondlevel:thirdlevel
    xmlns:secondlevel="http://secondlevel.com"
    xmlns:secondlevel:thirdlevel="http://thirdlevel.com">
</root:secondlevel:thirdlevel>

Is there a way to do those multiple levels root:secondlevel:thirdlevel as valid XML?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No, there can be at most one namespace prefix in XML.

The XML Namespace BNF rules for names are based on QName, which allows only a single PrefixedName:

QName          ::= PrefixedName | UnprefixedName
PrefixedName   ::= Prefix ':' LocalPart
UnprefixedName ::= LocalPart
Prefix         ::= NCName
LocalPart      ::= NCName
NCName         ::= Name - (Char* ':' Char*) /* An XML Name, minus the ":" */

Neither Prefix nor LocalPart allow colon (:) characters, so there can be at most one colon (and at most one Prefix) part to a QName.

Side note: multiple colons are syntactically allowed in base level XML:

STag          ::= '<' Name (S Attribute)* S? '>'
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
NameChar      ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
Name          ::= NameStartChar (NameChar)*

But the W3C XML Recommendation is clear that colons should not be used except for namespaces purposes:

Note:

The Namespaces in XML Recommendation [XML Names] assigns a meaning to names containing colon characters. Therefore, authors should not use the colon in XML names except for namespace purposes, but XML processors must accept the colon as a name character.

And Namespaces do not allow multiple namespace prefixes as shown above.

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...