user3792852
user3792852

Reputation: 355

XML: Namespaces in attribute values, is it a standard and how to work with them?

When working with XML, I often encountered attribute values that are qualified with a namespace, for example:

<tag xmlns:foo="http://foo.bar" att1="foo:value" />

I always wondered how far (or if at all) this is covered by the XML standard. The parsers I tried (Xerces and Saxon in Java or the XMLSpy's native parser) still report the XML as well formed even if you leave out a namespace declaration that is referenced in an attribute value.

So my question is: Is this usage of namespaces in attribute values covered by the XML standard (or an extension to it) or is it entirely up to the application's business logic to deal with it? ...also, if it is a standard, can you get any java parser to correctly check if a namespace prefix in an attribute value is correctly declared?

Upvotes: 1

Views: 90

Answers (1)

Michael Kay
Michael Kay

Reputation: 163342

If the attribute is declared in a schema as being of type xs:QName, then the schema validator will check that the attribute value is in the proper form for a QName and that the prefix has been declared. Otherwise, it's just an ordinary attribute as far as the XML parser is concerned, and any interpretation and validation as a QName is up to the application.

Upvotes: 2

Related Questions